• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

The JButton works for only click

 
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use .equals() instead of == to compare strings:


See:
AvoidTheEqualityOperator
Difference between == and .equals
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's possible that on the second time you click the button, the condition in the if is false.
 
We don't have time for this. We've gotta save the moon! Or check this out:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic