|
Re: Help With Text Field Labels
|
Posted: Jul 18, 2011 4:09 AM
|
|
Dear Owen Kelly,
These are the small small mistakes every one will do at the starting time of learning.
The Mistake the you have done was, i will explain with the example. eg: int i = 20; -------- -------- i = 30; -------- -------- i = 40; -------- --------
System.out.print("i-->"+i );
Will it print like this i= 20, i=30, i=40? it will print the last value(i.e i = 40) because you are continuosly re-assigning(keeps on chagning the value of i).
In the same manner, as like in the above example reassinging the "i" value, In your application you have reassinged the "inputLabel" and "resultLabel", so you are not getting the out put as you have expected.
// Here is the changed code snippet of "TempListener.java" // I have used the out put statements to console just for debugging purpose (as i know, using out put statements to console is good practise at the time of learning, not in Real Time Bussiness Applications)
private class TempListener implements ActionListener { public void actionPerformed (ActionEvent event) { double aTemp, bTemp, cTemp, discriminant, solution1, solution2;
String text = a1.getText(); String text1 = b1.getText(); String text2 = c1.getText();
aTemp = Double.parseDouble(text); bTemp = Double.parseDouble(text1); cTemp = Double.parseDouble(text2);
System.out.println("-A--->"+text+"- "+aTemp+"-------"); System.out.println("-B--->"+text1+"- "+bTemp+"-------"); System.out.println("-C--->"+text2+"- "+cTemp+"-------");
discriminant = Math.pow(bTemp, 2) - (4 * aTemp * cTemp); System.out.println("discriminant---->"+discriminant); solution1 = Math.sqrt(discriminant); //((-1 * bTemp) + Math.sqrt(discriminant)) / (2 * aTemp); System.out.println("solution1---->"+solution1); solution2 = ((-1 * bTemp ) - Math.sqrt(discriminant)) / (2 * aTemp); System.out.println("solution2---->"+solution2);
//resultLabel.setTe xt (Double.toString (solution1)); resultLabel.setText ("Result 1= "+Double.toString (solution1)+" Result 2 = "+Double.toString (solution2));
}
}
Kelly.. i think you have cleared your problem. if you have any doughts in java/j2EE get me on "kishore.podili@gmail.com"
|
|