• 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

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

 
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've done the splitting for John.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're probably missing a } somewhere.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)".
 
reply
    Bookmark Topic Watch Topic
  • New Topic