Results 1 to 3 of 3
- 12-24-2012, 02:45 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 23
- Rep Power
- 0
How to get text typed into a text box into a public string
Okay, so this is a really basic question that I'm sure has an easy answer. I'm trying to get some sort of data that can be accessed by other parts of my program from user input. I've made a JPanel to give my program a GUI and I could basically write the whole rest of the program if I could figure out how to make this chunk of code:
Put the data from the text box (userInput is a swing text box) into a publicly accessible variable. Unfortunately, the NetBeans compiler doesn't let me swap that method from private to public for some reason and when I try to copy/past that method earlier and modify the copy pasted method, I find I can't delete the original method, I can't even comment it out.Java Code:private void chooseButtonActionPerformed(java.awt.event.ActionEvent evt) { String text = userInput.getText(); int intEntered = Integer.valueOf(text); }
Thus I call on more experienced programmers for advice. If I can get any publicly accessible variable at all out of user input I can write code to translate it, I just need what the user types to modify a variable accessible to the rest of the classes that inherit from the GUI class.
What should I do? Any and all assistance would be appreciated.
-
Re: How to get text typed into a text box into a public string
Rather than put the data into a variable that has been declared in that method and is thus visible only in that method, consider putting that data into a non-static variable of the class, one whose value can be obtained by other classes via a getter method.
- 12-24-2012, 03:22 AM #3
Member
- Join Date
- Dec 2012
- Posts
- 23
- Rep Power
- 0
Re: How to get text typed into a text box into a public string
Hot dang! that worked perfectly, I'd tried something like this, but accidentally put the variable declaration in a constructor. Thank you so much Fubarable! I'm not sure what the count is on times you've pulled my butt out of the fire at this point, but it's getting up there.
Similar Threads
-
Find, Replace Text in Word Document & Retain Original Text Formatting
By saaspose in forum Java SoftwareReplies: 0Last Post: 07-24-2012, 08:07 AM -
How to Decrypt a Encrypted text file using public key?
By jayantb in forum New To JavaReplies: 1Last Post: 03-06-2012, 10:28 PM -
Reading from a text file, then writing back to Text Area in Reverse
By medic642 in forum New To JavaReplies: 8Last Post: 07-17-2011, 02:38 PM -
Transforming xml to text keeps placing blank line at beginning of text file
By DerekRaimann in forum Advanced JavaReplies: 7Last Post: 03-05-2011, 09:25 AM -
Applet program to open a text file and display the content in text area
By bitse in forum Java AppletsReplies: 0Last Post: 12-09-2010, 05:56 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks