swing - ActionListener in java performs action on the second click -
I'm programming my first complex application in Java, swing when I've added ActionListener to my JButton. ActionListener changeButton = New ActionListener () {@Override Public Null ActionPerformed (ActionEvent e) {if (startButton.getText () == "Spustit") {StartButton.setText ("STOP") ; } And {startButton.setText ("Specialty"); }}}
I'm adding the ActionListener to the button
Private Zero Startbutton ActionProperty {startButton .addActionListener (changeButton); } Can you tell me how I called the executive? Thanks for all!
You have done enough to codify ActionListener, at least, for the action listener itself . The problem is that you are adding action listener after an event (your second sample), thus your action listener will be asked for a second time, when you click it.
A solution is very simple:
button button = new pocket (); Button.addActionListener (New Exhibitist) {@Override Public Zero Improvisation (ActionEvent E) {// ...}});
Now the action listener should activate on the first click if you add a new action manager directly on the button, then not after action
Comments
Post a Comment