Win a copy of Fixing your Scrum this week in the Agile 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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: 3244
30
  • 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: 11445
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
 
What are you doing in my house? Get 'em tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic