I have the code below which creates a button and registers an event on it.When a button is clicked it writes a data into .csv file.The getFullName() etc methods return JTexField.getText(). When ALL of JTextFields I mean every single JTextFields are filled with user input then writeDataIntoFile() is called otherwise it returns a message "Empty fields left". The problem is If I fill only getFullName() - reference of JTextField, writeDataIntoFile() is getting called. Any suggestions how to fix this?
JButton registBtn = new JButton("register");
add(registBtn);
registBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
if (getFullName() != ("") && getRegNum() != ("") && //It doesnt matter if i use .equils()
getItemName() != ("") && getNote() != (""))
{
writeDataIntoFile();
}
else
{
JOptionPane.showMessageDialog(null, "Empty fields left.Please fill");
}
} catch (IOException ex) {
System.out.Println("E), ex);
}
}
});