So I am trying to get my GUI to work. When I run the code below, it does nothing, and I’m sure I’m probably just doing something dumb, but I am completely stuck…
public void actionPerformed(ActionEvent e){
UI.getInstance().sS++;
if((UI.getInstance().sS %2) != 0){
UI.getInstance().startStop.setName("STOP");
UI.getInstance().change.setEnabled(false);
}else if(UI.getInstance().sS%2 == 0){
UI.getInstance().startStop.setName("START");
UI.getInstance().change.setEnabled(true);
}
}
public void setStartListener(StartHandler e){
this.startStop.addActionListener(e);
}
sS is an int that increments every time the button startStop is clicked. change is also a button.
Here’s an example that shows a different approach to managing a
Start/Stopbutton. It uses an instance ofjavax.swing.Timerto pace updates. Encapsulating the control button and display label may simplify maintenance. This variation illustrates adding a third command to pause updates.More generally, use
Actionto encapsulate functionality for use elsewhere in your program. This example "exports several actions that make it easy to use them in a control panel."