• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Why nothing works after beep sound in java swing?  RSS feed

 
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want that user will hear beep sound and after it the textField will be empty when user  enter number or any nonword character (except white space and dash) . But after beeping nothing happens.I mean that the textField stay same and being not clean.For testing I  have written  this line (  System.out.println("here");  )  and it is not printing also. What is the problem? Can you help for this?
 
Marshal
Posts: 62231
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for using the code button but your middle line is too long to read easily. More information in the old Sun style guide.
I can't see what is wrong with that code; I think there must be an error elsewhere.

Moving to our GUIs forum.
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Thank you for using the code button but your middle line is too long to read easily. More information in the old Sun style guide.
I can't see what is wrong with that code; I think there must be an error elsewhere.

Moving to our GUIs forum.



I don't think so.Most probably the problem is just here.And this loop is inside of insertUpdate (method of document listener) method and line 4 is not working.The problem is not related with 3rd line because I comment 3rd line and 4th is not working still.Just I can't understand why textField is not cleaning.
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Thank you for using the code button but your middle line is too long to read easily. More information in the old Sun style guide.



Thank you too.I will pay attention to it
 
Sheriff
Posts: 23968
50
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Asif Haciyev wrote:Just I can't understand why textField is not cleaning.



My guess: that line of code clears a text field, but not the text field which you see in your GUI.

So look through the rest of your code to see if maybe you declare it twice, or create it twice, or something like that.
 
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried debugging by adding a print statement after line 1 that prints the value of c?
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:
My guess: that line of code clears a text field, but not the text field which you see in your GUI.

So look through the rest of your code to see if maybe you declare it twice, or create it twice, or something like that.



I have created it one time and there is no other texField which has the same name wtih this one.
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Have you tried debugging by adding a print statement after line 1 that prints the value of c?



I did it. But print stament prints the right char.I think problem is in the if block.How can I replace this if block with other one , but it needs to follow same conditions.
 
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're getting a beep it can't be the if statement since you're already pasted the conditions when the beep is executed.
The problem is that you're trying to refference a non-static textfied in a static context
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the just insertUpdate method but other methods ( I mean removeUpdate and changedUpdate) have the exactly the same code.When the user enter number or any nonword character (except white space and dash)
java.lang.IllegalStateException: Attempt to mutate in notification is throwed.How to fix that?

 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:If you're getting a beep it can't be the if statement since you're already pasted the conditions when the beep is executed



The three method (insertUpdate, removeUpdate and changedUpdate) is in one user defined method let's say beepSound(); and I call beepSound(); in class constructor.
 
Daniel Demesmaecker
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is you're trying to refference a textfield (which is non-static) from a static context. Lol never mind, I was trying to reference it from a stic context not you
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:The problem is you're trying to refference a textfield (which is non-static) from a static context



But beepSound(); method is not static.
 
Daniel Demesmaecker
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lol no it was my fault, i copied you're code to try and regenrate it but didn't notice that I paste it in the psvm method
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Lol not it was my fault, i copied you're code to try and regenrate it but didn't notice that I paste it in the psvm method



Lol,no problem
 
Daniel Demesmaecker
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used your code and for me it works ...



 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I used your code and for me it works ...



But what is the problem with my code? I got exception for this code and textField is not clean still.
 
Daniel Demesmaecker
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only difference between your code and mine is that I use an actionEvent on my button

Controller:
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:The only difference between your code and mine is that I use an actionEvent on my button

Controller:



But you have not used DocumentListener
 
Daniel Demesmaecker
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot modify the document inside the DocumentListener. Write a custom Document instead, which overrides the insertString() or remove() methods.

From Java Tutorials: How to write a DocumentListener:
Document listeners should not modify the contents of the document; The change is already complete by the time the listener is notified of the change. Instead, write a custom document that overrides the insertString or remove methods, or both. See Listening for Changes on a Document for details.

 
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:You cannot modify the document inside the DocumentListener. Write a custom Document instead, which overrides the insertString() or remove() methods.

From Java Tutorials: How to write a DocumentListener:
Document listeners should not modify the contents of the document; The change is already complete by the time the listener is notified of the change. Instead, write a custom document that overrides the insertString or remove methods, or both. See Listening for Changes on a Document for details.



I agree with Demesmaecker.
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:You cannot modify the document inside the DocumentListener. Write a custom Document instead, which overrides the insertString() or remove() methods.

From Java Tutorials: How to write a DocumentListener:
Document listeners should not modify the contents of the document; The change is already complete by the time the listener is notified of the change. Instead, write a custom document that overrides the insertString or remove methods, or both. See Listening for Changes on a Document for details.



I am sorry to be late.I understand this way but it didn't work for my me.
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Asif Haciyev wrote:

Daniel Demesmaecker wrote:You cannot modify the document inside the DocumentListener. Write a custom Document instead, which overrides the insertString() or remove() methods.

From Java Tutorials: How to write a DocumentListener:
Document listeners should not modify the contents of the document; The change is already complete by the time the listener is notified of the change. Instead, write a custom document that overrides the insertString or remove methods, or both. See Listening for Changes on a Document for details.



I am sorry to be late.I understood this way but it didn't work for me.

 
Daniel Demesmaecker
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What didnt work? What error did you get? What did you try?
 
Asif Haciyev
Ranch Hand
Posts: 35
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:What didnt work? What error did you get? What did you try?



I create a class which implements DocumentListener and I wrote all three methods there and in my Jframe I wrote textField.getDocument( new MyDocumentListener() );  and problem is that when I try to open the frame which has textField from my main frame  I doesn't open as though button doesn't work but actually button works well.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!