• Post Reply Bookmark Topic Watch Topic
  • New Topic

Popup for invalid input

 
Shiva Gajjala
Ranch Hand
Posts: 77
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends, I am doing my college assignment .I would like to restrict the user to enter integer or double value for dollar and display an error message saying "Enter valid number".

 
Campbell Ritchie
Marshal
Posts: 52516
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avoid addActionListener(this) which is non‑object‑oriented style. Anyway now you have λs you can write
There are several ways you can verify the input in the box. One is with a regular expression, which means you can verify that you have two places after the decimal point. Another is with a ScannerBeware: the Scanner will happily accept “1.234567890 Campbell” as correct input and return 1.23456789.
 
Campbell Ritchie
Marshal
Posts: 52516
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't extend JFrame. Use it unextended as a local variable in the constructor or setUpGUI method. Don't calculate your money in the frame. Set up a separate app which does the calculations and call that from the listeners. I do not think you need those other components as fields. They can be local variables too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!