Re: JComboBox Arrays not working
cassiemay wrote:
Hi all,
I am trying to get my JComboBox to initialize using arrays and I can
not get it to work. I've tried hard coding the values but it defaults
to the last if statement. Here is my ItemListener piece that is not
working.
[snip code]
Does anyone have any suggestions on what I need to correct to get it to
work? termvaluein and ratevaluein are apart of the mortgage
calculation. rate and term are the text field where the values need to
populate.
Many thanks.
This works for me..
private final String[] OPTIONS = {"Select Option","Option 1", "Option
2","Option 3"};
private final String[][] INTTERM =
{{"7","5.35"},{"15","5.5"},{"30","5.75"}};
private Integer termvaluein;
private Double ratevaluein;
jComboBox.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent evt)
{
if (evt.getStateChange() == ItemEvent.SELECTED)
{
if (evt.getItem().equals(OPTIONS[1]))
{
termvaluein = Integer.parseInt(INTTERM[0][0]);
ratevaluein = Double.parseDouble(INTTERM[0][1]);
System.out.println("Option 1 - termvaluein = "
+ termvaluein + "ratevaluein: " + ratevaluein);
}
else if (evt.getItem().equals(OPTIONS[2]))
{
termvaluein = Integer.parseInt(INTTERM[1][0]);
ratevaluein = Double.parseDouble(INTTERM[1][1]);
System.out.println("Option 2 - termvaluein = "
+ termvaluein + "ratevaluein: " + ratevaluein);
}
else if (evt.getItem().equals(OPTIONS[3]))
{
termvaluein = Integer.parseInt(INTTERM[2][0]);
ratevaluein = Double.parseDouble(INTTERM[2][1]);
System.out.println("Option 3 - termvaluein = "
+ termvaluein + "ratevaluein: " + ratevaluein);
}
}
}
});
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)