Swing Question, can you help?
Ok, so I'm trying to understand Swing a bit better. I've created a container and all that good stuff, but what I'm trying to accomplish is:
Creating a button that will add text on to the Frame when pressed. I accomplished this by defining the following:
public void display() {
JLabel dis = new JLabel("Acknowledged");
add(dis);
setVisible(true);
}
public void actionPerformed(ActionEvent evt) {
String cmd = evt.getActionCommand();
if (cmd == "Show") {
display();
}
So here's the brain-tickler, When I press the button it does display the text as a JLabel in a FlowLayout fashion. When I press the button again it adds another in another, and another, and so on.
So here's the question: What can I try to only have the button display one Jlabel only, and then do nothing when it's pressed again? Input would be greatly appreciated because I'm a noob to Java, it's my first computer programming language.