wood burning stoves*
The moose likes Beginning Java and the fly likes JLabel1.setText error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JLabel1.setText error" Watch "JLabel1.setText error" New topic
Author

JLabel1.setText error

Mike Meakin
Ranch Hand

Joined: Dec 30, 2004
Posts: 88
Can anyone tell me why I am getting an error with this line, line 82:

jLabel .setText(Math sqrt(double(jTextField1.getText() );

it just keeps saying I need another ')' but that doesn't make any difference no matter how many '('s I put in in just says I need another one.
Heres the full code:


//JAM -- added [CODE] and [/CODE] tags
[ March 18, 2005: Message edited by: Joel McNary ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Originally posted by Michael Munro:
Can anyone tell me why I am getting an error with this line, line 82:

jLabel .setText(Math sqrt(double(jTextField1.getText() );

it just keeps saying I need another ')' but that doesn't make any difference no matter how many '('s I put in in just says I need another one.


If you keep putting in open-parens, the error will never go away. Do what the message says and put in more close-parens. You've got 4 opens, you need 4 closes:


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

and don't forget the period after Math

looking closer at it, I see even more errors.

First, you have to convert the String to a double.
Then, you have to take the double that's teh drqure root and convert it back to a String. I'd break the statement apart in order to have better control over this:

Mike Meakin
Ranch Hand

Joined: Dec 30, 2004
Posts: 88
Hey Joel, I tried that and got these errors:

"Frame3.java": Error #: 300 : method jTextField1_actionPerformed(java.awt.event.ActionEvent) not found in anonymous class of method jbInit() at line 48, column 9
"Frame3.java": Error #: 354 : incompatible types; found: java.lang.Double, required: double at line 82, column 32
[ March 18, 2005: Message edited by: Michael Munro ]
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
Haven't looked at your code but as for the error messages the second one is pretty obvious. Double does not equal double (note the capitalization). Go to line 82 and switch Double to double.

Okay looked at your code now and as for the first error message it's just what it states. You haven't created a method named "jTextField1_actionPerformed", yet you're trying to access it.
[ March 18, 2005: Message edited by: Hentay Duke ]
Mike Meakin
Ranch Hand

Joined: Dec 30, 2004
Posts: 88
Great, so how do I create that method?
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Sorry...use .parseDouble instead of .valueOf. (The former returns the primitive, the latter returns the wrapper type.)
Mike Meakin
Ranch Hand

Joined: Dec 30, 2004
Posts: 88
Well that leaves me with ths error:

"Frame3.java": Error #: 300 : method jTextField1_actionPerformed(java.awt.event.ActionEvent) not found in anonymous class of method jbInit() at line 48, column 9

Thats relating to this lne:

jTextField1_actionPerformed(e);
Mike Meakin
Ranch Hand

Joined: Dec 30, 2004
Posts: 88
Basically what I need is a code for jButton1 so that when I type a number into jTextField 1, I can then press jButton 1 to calculate the square root.
The answer then needs to show in JLabel1. Any ideas ???
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Back to your original question, it looks like you are trying to do too many things in a single line of code. This often leads to missing closing-parens as well as numerous logic errors. I'd strongly suggest that you break that one line of code into several lines. You can use temporary variables to store the intermediate results of each step. For example:

Personally, I find this code much easier to read and deal with. For one thing, it makes it easier to find causes of compiler errors. It also allows you to add System.out.println() calls or add watches in a debugger in order to see intermediate results.

If you make similar changes to your code above, I think you will find that you can fix many of the errors yourself.

Keep Coding!

Layne


Java API Documentation
The Java Tutorial
Mike Meakin
Ranch Hand

Joined: Dec 30, 2004
Posts: 88
Well I tried that and got these errors:

"Frame3.java": Error #: 300 : method jTextField1_actionPerformed(java.awt.event.ActionEvent) not found in anonymous class of method jbInit() at line 48, column 9
"Frame3.java": Error #: 300 : variable jLabel not found in class untitled2.Frame3 at line 85, column 3

what ever code I use I always get an error in line 48,what do I need to do to solve this?
Mike Meakin
Ranch Hand

Joined: Dec 30, 2004
Posts: 88
Thanks for the help People, your all amazing! it works now!
 
Consider Paul's rocket mass heater.
 
subject: JLabel1.setText error