aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes If statement not working for dropmenu calculations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "If statement not working for dropmenu calculations" Watch "If statement not working for dropmenu calculations" New topic
Author

If statement not working for dropmenu calculations

Angel eyes
Greenhorn

Joined: Aug 30, 2009
Posts: 1
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

Joined: Jun 13, 2009
Posts: 2203
    
    7
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

Joined: Jul 26, 2007
Posts: 10451
    
    8

Angel eyes wrote:

Please check your private messages for an important administrative matter


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: If statement not working for dropmenu calculations