wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Clicking works, but pushing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Clicking works, but pushing "enter" return errors...how to fix? (on a button named "Enter")" Watch "Clicking works, but pushing "enter" return errors...how to fix? (on a button named "Enter")" New topic
Author

Clicking works, but pushing "enter" return errors...how to fix? (on a button named "Enter")

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

The problem: When I click "Enter", the program runs fine 100%. When I push "enter" when the "Enter" button has the focus, it returns errors. Everything else works 100% fine. Please help me with this problem:
Risk.java:

RiskApp.java

Thanks,
cc11rocks

EDIT: The errors are system errors. What I want to be done is put 0 in all fields. This is the error I get:


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

john price wrote:

On line 44 of file Risk.java, you are calling parseInt with an empty String as the argument. It's as simple as that. stupid.getText() returns "" so the field is still empty.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

That sucked to code...Is there anyway to clean up my code? It is super messy. Should I start using methods and stuff or does this work. Is there any more possible kinks that a user could screw up (such as entering a non-integer or leaving the field blank)? Any advice? Here is my lastest version of Risk.java (I'll be working on RiskApp.java for the Menu's especially, and implementing an applicable spacer for the numbers so they can be on two lines, not just one. The only way currently to have them on two lines is to make the numbers long. I plan to implement this by creating new strings, finding the length of them and then using that number to spaces. If you know of a better way to do this, please share.)
Risk.java (At 250 lines, this is the longest Java program I have ever written, although I've hit in the thousands for Autohotkey due to support for multiple configurations of computers.)

With much appreciation,
cc11rocks
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
@John,

I can't even read your question because of the horizontal scrolling required to read each line of your question.

I suggest you fix line 36 in your code so that your hard coded string is split up onto multiple lines. Something like:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

I've done the splitting for John.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Rob Camick wrote: . . . I can't even read your question because of the horizontal scrolling required to read each line of your question.

I suggest you fix line 36 . . .
There was worse formatting in the first post. About 5 statements including ifs without {}, all joined together to form a single line inside a switch-case. Really dreadful formatting, which makes the code very difficult to read. I have sorted that out.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Thank you very much guys. I really appreciate it!
EDIT(Wasn't being sarcastic): With the current code you give me, it returns 14 errors:

cc11rocks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

You're probably missing a } somewhere.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Not blaming here, but you guys changed the code. In fact I asked you guys to clean it up, which you did. It's not compiling and i can't find the problem. If you need a working version, I will be happy to provide it.
Thanks,
cc11rocks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

I changed one line of code, the one setting the tool tip, and that was not the cause of this compiler error.

If you would add better indentation you would see that you're missing a } at line 117. The "if (setgood)" has a nested "if (setbad) else" block. Line 117 is the else that should belong to the "if (setgood)" but you forgot to close the "if (setgood)" first. That means that this else too belongs to "if (setbad)".
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Clicking works, but pushing "enter" return errors...how to fix? (on a button named "Enter")