• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

If statement not working for dropmenu calculations

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having trouble with my if statements being overlooked or something. In the code below for case 0, case 1 and case 2. I have a menu the user selects and it is to calculate depending on what the user selects. It calculates the same thing no matter which options is chosen. Could someone please let me know where I am going wrong. I am new to this and have spent many hours trying to adjust my code to calculate correctly. Thank you in advance for helping me with this.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I don't know what a "drop menu" is. Where in the API or documentation do you see that term?

I am new to this and have spent many hours trying to adjust my code to calculate correctly.



Well, then learn to simplify the problem.

I assume you are talking about a combo box, so create a simple JFrame with a single combo box. Then learn how to write simple test code for only that one component that simply displays a different message for each item select.

Then once you understand the basics of using a combo box you apply the knowledge to your real program. Its called a SSCCE.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Angel eyes wrote:


Please check your private messages for an important administrative matter
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> I am having trouble with my if statements being overlooked or something.

are you sure?

debugging 101, add 1 or more System.out.println()'s to see what values the program is working with.

first up would be
System.out.println("Combo selected index = "+selected);

run the program, select the first item, 'calculate' and see what prints
select the second item, 'calculate' and see what prints

if the same value is printed, backtrack the comboBox and you should find the problem
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic