Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If statement not working for dropmenu calculations

 
Angel eyes
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.

 
Rob Camick
Ranch Hand
Posts: 2616
9
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angel eyes wrote:

Please check your private messages for an important administrative matter
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic