• Post Reply Bookmark Topic Watch Topic
  • New Topic

Gui JTextBoxes to a numerical array  RSS feed

 
Dee Heat
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner. I have created the GUI interface required but there seems like there has to be an easier way. I also don't know how to get the input from the textboxes turn them into doubles and store them in an array. Here is my code.

 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I suggest you create an array of response's instead of declaring each one separately.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Is there anything helpful in the Java® Tutorials? (Actually probably nothing which addresses your current problem.)
You know you can get the text out of a text component easily enough with its get methods. Then you can pass the text to a Scanner or use a parsing method.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use a Scanner you can verify that the text constitutes a double without risking any Exception.
 
Dee Heat
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try to run the array it will compile but it will not execute. Can I run a get/set method in a loop?

 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have

You will end up in an infinite loop because 'y' is not incremented in the loop. Adding braces would have fixed this. Perhaps a better way to express this is

A nitpick, I would have used the plural form "responses". Also 'y' is declared too many lines before your loop which makes it harder to find and then you have to look through all those lines to see if 'y' was modified.

Edit: PLEASE use code tags when posting your code.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a link about using code tags: UseCodeTags. I edited the first post to show you how much better using code tags is; could you edit your other post with code in it? Thanks.

Edit: Campbell beat me to it.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also broke some of the worst long lines; (please note how to do it), and deleted some of the excess multiple empty lines.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!