Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

changing the output of a button between two alternate values

843805Jan 20 2006 — edited Jan 20 2006
Hi,

I'm writing a basic swing program and need a button which will alternate between two values. Each value will then be added to the text label beneath the button.

eg: press the button the first time and the text beneath will write 'Increment'. Press the button again and it will write 'Decrement', and so on.

I know how to output one value to a label, but I'm not certain how to get the button to alternate between the two values.

My current code is as follows,
 static private class IncrementDecrementAction implements ActionListener {       
       public void actionPerformed(ActionEvent e) {
            SwingApplication2.label.setText(labelPrefix + "Increment");
          //SwingApplication2.label.setText(labelPrefix + "Decrement");
        }
    }
Any ideas how I can change this to include alternating between 'Increment' and 'Decrement'.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2006
Added on Jan 20 2006
10 comments
64 views