This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Submitting info using a button

 
Scott Kimberly
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i have 4 text fields that a user can input numbers into.

I want to use the button associated with these text fields to submit the info from the fields to 4 variables outside of the method.

Im having trouble setting up the method so that it sends back the user's input.



right now thats what i have for the method, but it doesnt return the assignments. How do i alter this to return the 4 ipSeriesOne etc variables?
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what you mean by "sends back the user's input". Where is it supposed to send it back to?

You do seem to be assigning data to four variables, which I expect was what you meant by "submit the info". Otherwise I don't understand what you are trying to do.
 
Swetha Popuri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, to make things more clear, can you post the form code also.
 
Scott Kimberly
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my gui code for this button and winow.



I want to take the information (numbers the user inputs) from the 4 text fields using the .getText() method on each when i click my button. I want this information to be stored and used in a different spot.

What im basically trying for is to prompt the user to enter and IP address using 4 text fields. each field is part of the IP. Clicking the button should take that info, store it in one of 4 variables, and then something else will call those variables to see what they contain.

Im having trouble getting the actionListener code to work properly to make the button functional.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. Then so far from those code fragments, the action listener is written to assign the contents of four text fields to four variables. That looks okay to me. What problem do you see?
 
Scott Kimberly
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so now i see better what my issue is.



The sock = new Socket line, generically, should real sock = new Socket ("127.0.0.1", 5000); for the local host.

What im trying to do is take those 4 variables and plug them in here, but i dont think im doing this properly.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


ipSeriesOne etc are the textField's themselves, click this link JTextField, then check the methods,
and inherited methods, for some method that will get you the text
 
Swetha Popuri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ipGroupOne.. This is the name of the textField.
I am not sure why you have a new class created for the event itself. See if you can try this

private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
String str = ipGroupOne.getText();
System.out.println("This is the text " + str);
}

This works
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!