• Post Reply Bookmark Topic Watch Topic
  • New Topic

The JButton works for only click  RSS feed

 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am coding an alarm application.
I use a JButton to set the alarm. I use the same JButton to warn the user about choosing any file other than an "mp3" file for alarm ringer. But the button works only once.
Here is the code


But I want the button to work as many times as user selects a file other than an mp3 file. Can somebody please help me with this
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use .equals() instead of == to compare strings:


See:
AvoidTheEqualityOperator
Difference between == and .equals
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember the (==) comparison is object comparison, it checks if the objects on both sides of the == signs are the same.
The .equals() method compares the string value of the string objects, which is what you want to compare.
 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Use .equals() instead of == to compare strings:


See:
AvoidTheEqualityOperator
Difference between == and .equals


Thank you very much for the suggestion. Can you help me out with my main problem also?
 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unnar Björnsson wrote:Remember the (==) comparison is object comparison, it checks if the objects on both sides of the == signs are the same.
The .equals() method compares the string value of the string objects, which is what you want to compare.

Thank you,can you help me out with my main problem?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you elaborate on what happens when you click the second time?
 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith Lynn wrote:Can you elaborate on what happens when you click the second time?

The second time I press the button nothing is happening
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried printing out something at the beginning of actionPerformed to see if it may be getting there?
 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith Lynn wrote:Have you tried printing out something at the beginning of actionPerformed to see if it may be getting there?

But its working first time.Do I have to put it in any loop?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's possible that on the second time you click the button, the condition in the if is false.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!