This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Help with creating GUI Error Messages.  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an assignment where I must modify my code to:
A: If the weight of an object is greater than 99999 your code should print a GUI driven error message, and force the user to reenter the weight of the object.
B: If a user enters a negative weight, your code should display a GUI warning message.

My original code is:




Not sure if its needed, but the Weight class is:



I thought in order to add the error message pop ups it would require an IF statement. I came up with:



The entire code with the addition looks like:



When I run the program it runs just the original program. It does not recognize if I enter a number higher than 99,999 or less than 0 and performs the calculations as normal. I am completely unsure as to what I am missing. Any help pointing me in the right direction would be greatly appreciated.
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you not understand my suggestion in the other forum? If not, please describe your confusion and ask additional questions in the original post.

Edit:

My suggestion from the other forum:

You need some kind of loop to repeat the request for the object's weight if the user's entry is incorrect, something like:
 
Ryan Childs
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haha, no, just thanks to the Wifey I lost browser history and could for the life of me not recall the site.

Anyways, you suggested the do-while loop.

I was working on that and could not figure out the proper way to construct it.

I understand I need to have for lets say the "A" portion:



However the bit about setting parts to false and true completely lost me. Also I am unsure where the do-while loop is suppose to fit in the original code.

Again my bad on switching to a different site, awesome that you are here as well though! (would love the name of that other site too)
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have the construct of the do/while loop correct, and you could do it the way you've coded. I suggested using an error flag, a boolean called 'error', so that multiple conditions could be tested in a single loop with the minimum or simplest (in my mind) code. Since you want to test for both greater than and less than a certain amount, your while statement should look like:

while( ObjectWeight > 99999 || ObjectWeight < 0 );

so that the do loop will continue to execute, asking the user for the object's weight, until a correct number is entered.

I'll PM you the other site.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perhaps you could work (compare notes) with this poster

http://www.coderanch.com/t/565460/GUI/java/Help-GUI-assignment
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!