Skip to Main Content

New to Java

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!

javax.swing.timer

807599Jan 8 2007 — edited Jan 9 2007
I have a button and a timer in a gui program. I want the timer to trigger events and the button to trigger different events.

The button works fine but I am having trouble adding the timer event to the action listener.

Here is the code I am trying in the Action Listener. I am expecting the code in the catch to run when the timer trigers. I am using a try catch handler because the e.getActionCommand needs an action command from the timer and I do not know what it is, it appears to be "null".

The Timer does trigger the catch and so I know that the Action Performed code is trying to run for the timer.

  public void actionPerformed(ActionEvent e) {
        try{
          System.out.println("e is " + e);
     if (e.getActionCommand().equals("Exit")) {
        this.myExit();
    }
}
 catch(Exception excp) {
         j.restart();
// j is my Timer
           System.out.println(excp + "excp " + e);
        }
 
    }
Where am I going wrong?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 6 2007
Added on Jan 8 2007
32 comments
152 views