Results 1 to 2 of 2
- 03-23-2009, 08:08 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 38
- Rep Power
- 0
ActionListener run automatically problem
Hi, something weird happen to my program.
Before I click the button, it seems that the program run my action listener automatically. The ....This shouldnt happen to appear on the console before button clicked...appear in the console before the button clicked.
What is wrong with the code?
and another weird thing happen the last else also shown in the console...but I only have 2 buttons.
Java Code:...... buttonX.addActionListener(this); buttonY.addActionListener(this); public void actionPerformed(ActionEvent e) { ..... System.out.println ([COLOR="Blue"]"This shouldnt happen to appear on the console before button clicked[/COLOR]"); if(e.getSource ()==buttonX) System.out.println ("Answer 1") else if (e.getSource()==buttonY) System.out.println ("Answer 2") else [COLOR="Blue"] System.out.println ("This should not happen");[/COLOR] ...... }Last edited by cassysumandak; 03-23-2009 at 10:17 PM.
-
Similar Threads
-
Application automatically terminates
By PaulT in forum EclipseReplies: 4Last Post: 03-18-2009, 05:02 PM -
ActionListener Applet problem
By xander5511 in forum Java AppletsReplies: 1Last Post: 02-21-2009, 03:42 AM -
Java actionlistener help
By justsomeguy in forum AWT / SwingReplies: 1Last Post: 05-27-2008, 05:42 AM -
Demonstrating the ActionListener
By Java Tip in forum java.awtReplies: 0Last Post: 04-23-2008, 08:20 PM -
Call a Method Automatically
By rhm54 in forum New To JavaReplies: 4Last Post: 02-07-2008, 08:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks