• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JLabel1.setText error

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:
 
Joel McNary
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great, so how do I create that method?
 
Joel McNary
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry...use .parseDouble instead of .valueOf. (The former returns the primitive, the latter returns the wrapper type.)
 
Mike Meakin
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ???
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mike Meakin
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help People, your all amazing! it works now!
reply
    Bookmark Topic Watch Topic
  • New Topic