• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with ActionListeners, cant get it to work.  RSS feed

 
Manne Bezum
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
I'm working on a small thing, nothing special. But I cant get my buttons to respond to clicking them.

Here's my code:




MAIN METHOD:
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags. You can edit your post to add them. I would do it for you, but then your variable names get completely screwed up. As a matter of fact, it's not a good idea to use non-ASCII characters at all for variable names.
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain what you want and what is going wrong.
 
Manne Bezum
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Codetags fixed.
Non-ascii characters or not that isnt the case here. It doesnt matter really since the characters will be replaced if non-existant.

The problem as I said in the beginning of my post is that when i press my button, or rather the JButton

Nothing happens. The actionlistener class is the following for the forementioned button:


So I cant find any errors in the above code, no compiling error either. So i just need some help why this code isnt working.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say
Nothing happens.

do you mean that even the JOptionPane is not displayed, or that 'Nothing happens' thereafter?

If the latter, it's because the return value of a JOptionPane.showConfirmDialog(...) displayed with OK_CANCEL_OPTION will never be equal to YES_OPTION, resulting in the actionPerformed(...) method returning without doing anything useful.
 
Manne Bezum
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe i was unclear when i said by nothing but i mean that the joptionpane dialog doesnt even show up when pressing the button with the actionlistener
 
David Byron
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem as I said in the beginning of my post is that when i press my button, or rather the JButton Nothing happens.
...
So I cant find any errors in the above code, no compiling error either. So i just need some help why this code isnt working.


It appears that you're adding an ActionListener to the tidKnapp button two times, and that you're adding the NyLyss ActionListener to the nyKnapp button zero times. As a result, clicking on nyKnapp does exactly what you're telling it to do: nothing.
 
Manne Bezum
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Byron wrote:
The problem as I said in the beginning of my post is that when i press my button, or rather the JButton Nothing happens.
...
So I cant find any errors in the above code, no compiling error either. So i just need some help why this code isnt working.


It appears that you're adding the NyLyss ActionListener to the tidKnapp button two times, and that you're adding the NyLyss ActionListener to the nyKnapp button zero times. As a result, clicking on nyKnapp does exactly what you're telling it to do: nothing.



Oh my, thanks for the spotting, i've been looking myself blind for errors. It worked now. Thanks a bunch! Even though it was a rookie mistake
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The real mistake is not that you are adding the Listener to the wrong button. The real mistake is that you are writing hundreds of lines of code. You should set up one button, add its Listener, and execute the code. Make sure the one Listener works, then yo can add the second button.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!