I'm having trouble getting the last few lines to work ,i.e; These Lines: Double.parsedouble(); jLabel1.setText((Double.parseDouble(jTextField1.getText())*0.166));
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
posted
0
Hi Michael, In your Code Double.parsedouble();
Should be like Double.parseDouble(String s) This method returns a new double initialized to the value represented by the specified String.
Well I tried that and it did't work, Thanks anyway... [ February 24, 2005: Message edited by: Michael Munro ]
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
Can you provide some more details? What do you mean "it didn't work"? Did it compile? If not, copy-and-paste the compiler errors here and we can explain what it means. If it compiled, did it run? Did you get any runtime errors or exceptions? If so, post the stack trace here. If you got output, how did it differ from what you expected?
The more details you can provide the more likely we will be able to help fix the problem. It is difficult to even start guessing how to help you with a statement as vague as "it didn't work."
Here the errors: "Frame1.java": Error #: 300 : method parseDouble() not found in class java.lang.Double at line 82, column 8 "Frame1.java": Error #: 300 : method setText(double) not found in class javax.swing.JLabel at line 83, column 9
-Its just those 2 lines
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
posted
0
Hi Michel, Can you please read my previous post again.
java.lang.Double has a method called parseDouble(String s) , it takes a String as an argument. Check your code at line 82, where you haven't passed the String argument.
In the Same way javax.swing.JLabel has a method called setText(String text) which even takes a string as an argument. See in your code at line 83 you have passed a double instead of String.
Note : i'm not sure whether the line number mentioned by me are correct, i just got it from the error message you have posted. Also in the beginner stage ( even after becomming a Java pro ) it's advisable to have the java API & solve errors like "method not found" which in turn helps people to get into the Java classes & methods strongly.
[ February 24, 2005: Message edited by: Srinivasa Raghavan ]
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
posted
0
Remove the line that Srinivasa pointed out:You are using parseDouble() correctly in the line after it, so remove the commented line. The method requires a String.This means the compiler cannot find a parseDouble method that takes no parameters.Similarly, JLable doesn't have a setText method that takes a primitive double. It does have one that takes a String, and the Double class has a method to convert a double to a String. There are other ways to do it too:If you don't like the format it uses, you can create your own with java.text.NumberFormat. Check the JavaDocs for more information on these classes and methods.
Mike Meakin
Ranch Hand
Joined: Dec 30, 2004
Posts: 88
posted
0
Ok I know I've got the code right now, and as silly as it sounds the main class won't work, any ideas what class I should run this as?
/**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void jButton1_actionPerformed(ActionEvent e) { jLabel1.setText(jTextField1.getText()); }