Hello guys, I'm fairly new to Java. I have been asked to create a simple GUI (JLabel, JTextField and 3 JButtons)
I have managed to create the GUI but I'm having trouble with making the buttons work.
Here is my actionPerformed method:
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource().equals(printButton)) // This is the first button. It should print the text in the JTextField
{
System.out.println(inResult.getText());
}
if (bgColour) // The second button (colourButton) should set the JTextField background to Red/White
{
bgColour = false;
inResult.setBackground( Color.white );
}
else
{
bgColour = true;
inResult.setBackground( Color.red );
}
if (disableText) // ...and the last button (editableButton) should enable/disable the JTextField
{
disableText = false;
inResult.setEditable(true);
}
else
{
disableText = true;
inResult.setEditable(false);
}
I would like to add that if I only include the code for the second or third button, they work. I'm not sure if I can have more than one statement in my actionPerformed method, because if I use 'if, else if' only the first button is triggered'.
Thanks in advance! :)