• 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

Java Name Swing Applet

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is my code. I must create a program that will take the inputted name and put it into standard form. I have many errors with my variables and my "nameInputActionPerformed" method. Does anyone know where I went wrong?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lexi Turgeon wrote:I have many errors with my variables and my "nameInputActionPerformed" method. Does anyone know where I went wrong?



Well, there are certainly lots of compiler errors there... but instead of just telling you, how about you tell us what the compiler error message are? And of course, this is so that we can help you interpret it, and understand how to fix it.

Henry

PS.... welcome to the ranch.
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My errors from my compiler are:

 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lexi Turgeon wrote:My errors from my compiler are:



This is a syntax error. In this case, the compiler believes that this section of code is no longer defined in a class, and is expecting you to start a new class or interface definition.

This is generally caused by mismatched parenthesis. You probably have one too many close parenthesis, that closed the class definition itself.

Additionally, the compiler is completely confused at this point. So, the rest of the errors may not even be valid. Just work on the first compiler error.

Henry
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have edited a few things but come up with some compiler issues that I do not understand.

Here is my code:


Here is what my compiler says is wrong:


 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

error: reached end of file while parsing


Check that the {}s are properly paired.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lexi Turgeon wrote:I have edited a few things but come up with some compiler issues that I do not understand.

Here is what my compiler says is wrong:



Agree with Norm. This is also a syntax error. The compiler still thinks that the class isn't complete. This is also formed by mismatch parenthesis, but in this case, you don't have enough close parenthesis.

Henry
 
Marshal
Posts: 79180
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:. . . Check that the {}s are properly paired.

The eaiest way to do that is to indent the code correctly, which you can probably do with a ctrl combination in NetBeans, and hover your mouse over a { and see which } changes colour. Your indentation in the posted code is not quite consistent and that makes it easy to mismatch {} without noticing.
Hint: class interface or enum exected at the end of the code: too many } or too few {
reached end of file…: too few } or too many {
class interface or enum expected at the start of the code: some sort of spelling error.
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So after those second corrections I only have one problem left from my compiler.



And this is my updated code:



The line " nameOutput.setText(newName); " has the "newName" underlined in saying it is wrong. I am trying to call that from my "convertNameActionPerformed". Why is what I put wrong and how would I fix it?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lexi Turgeon wrote:
The line " nameOutput.setText(newName); " has the "newName" underlined in saying it is wrong. I am trying to call that from my "convertNameActionPerformed". Why is what I put wrong and how would I fix it?



The compiler is complaining that it can't find the declaration for "newName" anywhere. And looking at your code, the compiler is correct. You don't have any "newName" variable in scope for that line.

Henry
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would I declare it so that I can get it from the method above? Would I just call that method?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What is newName supposed to be?  Did you mean yourname?
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yes, you were right. Now that my code is all working, the program does not run. Great.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Does not run", does it get an error?  What is the error?  If not, what exactly happens?
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I try and run the program with no errors in the code this is what the compiler says is wrong:

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lexi,

Where is nameInputActionPerformed called? Judging by the
parameter you passed into it, you have the following import:

import java.awt.event.ActionEvent;

I bet the function line doesn't need all the . operators, it could be

private void nameInputActionPerformed(ActionEvent evt)

Not to mention, that function has no use of the variable evt, so it could
operate with no parameters.

I assume you have “nameInput” and “nameOutput” declared somewhere.
You also should check for a null before reaching into a member.
For now, I would write the function like this:

private void nameInputActionPerformed()
{

if (nameInput != null && nameOutput != null)
nameOutput.setText(nameInput.getText());

} // That's it. Check both variables for null, and you don't need
// to declare a string to hold getText(), it can go in immediately.
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cooper Gates wrote:. . . I bet the function line doesn't need all the . operators, it could be

private void nameInputActionPerformed(ActionEvent evt)

I think that is code written automatically by NetBeans and it defaults to using the fully‑qualified name of the class. It may be impossible to change that code without moving it out of NetBeans.

. . . You also should check for a null before reaching into a member. . . .

Why? The fields shou‍ld have been initialised to “real” values before that code it executed. If there is a null anywhere, it will be necessary to alter the source code to correct the error. I would think it is correct to wait for an exception and assume all is well if no exception is thrown.
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cooper Gates wrote:. . . you don't need to declare a string to hold getText(), it can go in immediately.

That is a style matter where there are differing opinions.
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All the code is generated when I create the design of the project I want. I thought maybe it was something that I did not initialize in the design. I am not sure what else it could be.
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lexi Turgeon wrote:All the code is generated when I create the design of the project I want. . . .

Yes, all that code is generated automatically by the GUI designer when you give it the placement of the Components. When you click a component and tell it to add a Listener, it writes the appropriate method automatically. I think the GUI designer will cause most of that code to revert to its previous state if you try to change anything.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to see the code for NewJApplet.init, especially line 47.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cooper Gates wrote:
private void nameInputActionPerformed()
{

if (nameInput != null && nameOutput != null)
nameOutput.setText(nameInput.getText());

}


Could you please UseCodeTags (that's a link) when you post code?
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any idea how I would solve my errors?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:I'd like to see the code for NewJApplet.init, especially line 47.


Could you post the above code and we'll see what we can do.
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:I'd like to see the code for NewJApplet.init, especially line 47.



 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help. I had selected the wrong item when formatting the GUI.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic