Results 1 to 7 of 7
Thread: retreiving text
- 01-24-2012, 03:38 PM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 235
- Rep Power
- 3
retreiving text
I am prompting a user for a response in my program. here is my code that puts in the prompt:
and then the method:Java Code:String answer = gui.askGetInput("There were errors creating the file. Would you like to continue ahead with diagnostics? (Type \"y\" or \"yes\", or \"n\" or \"no\".) This will only take a minute.");
i tried adding this inside the actionPerformed:Java Code:public String askGetInput(String outText) { // Update textArea with question writeToTextArea(outText); jbtnSubmit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { // Wait for the user to respond, and press the submit button } }); return uI.getText(); }
But i got this error:Java Code:userInput = uI.getText();
How can i work this, so that i can return a value once as the user hits submit? i know i can't return anything in the actionPerformed method...Java Code:Cannot refer to a non-final variable userInput inside an inner class defined in a different method
Last edited by droidus; 01-24-2012 at 03:41 PM.
- 01-24-2012, 03:41 PM #2
Re: retreiving text
With this approach, you won't be returning anything. More likely, you'll be calling a separate function that indicates the user has pressed the button and the program should continue. You might also want to look into using a dialog though.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-24-2012, 03:42 PM #3
Senior Member
- Join Date
- Feb 2011
- Posts
- 235
- Rep Power
- 3
Re: retreiving text
why would a dialog be better? what would be some benefits of that? i thought it may get annoying everytime i wanted to ask them for something, a pop-up would appear.
- 01-24-2012, 03:46 PM #4
Re: retreiving text
The benefits are that a dialog can block the main window and allow you to return a value from that method. Your approach will not. I understand why you're taking your approach, but if you want to be able to return something from that method, a dialog is the way to go.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-24-2012, 03:48 PM #5
Senior Member
- Join Date
- Feb 2011
- Posts
- 235
- Rep Power
- 3
Re: retreiving text
hm, would there be a better way about designing this program that you would recommend? or is the dialog definitely the way to go?
- 01-24-2012, 03:52 PM #6
Re: retreiving text
It's really up to you. I feel you on the annoyance with too many dialogs. You can take your approach, but you won't be able to just return a value- you'll have to do whatever blocking of the GUI you need to do (if any), then respond appropriately when the user presses the button. It's not really complicated, it's just different from what you seem to be expecting.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-24-2012, 03:57 PM #7
Senior Member
- Join Date
- Feb 2011
- Posts
- 235
- Rep Power
- 3
Re: retreiving text
basically, to give a general overview, my program is a tasks manager. it asks if you would like to edit, list, delete tasks. from there then, it takes action. what task number would you like to delete? which one would you like to modify? please modify each field to modify the existing task. i was thinking maybe something like text fields for when modifying a task, so that i could just print to these text fields so they can easily modify them. anyone else have any other ideas?
Similar Threads
-
Retreiving value from a for-loop
By BariMutation in forum New To JavaReplies: 3Last Post: 10-12-2010, 10:24 PM -
Help in retreiving database data using a loop
By danpj in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 07-17-2009, 08:49 AM -
Retreiving of mail body using mail number
By chandu.v09 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-13-2008, 02:25 PM -
Retreiving list of keys from Map with certan value
By desmond5 in forum New To JavaReplies: 1Last Post: 03-06-2008, 08:10 PM -
Plz help ... retreiving data from an access database table....
By austinsmiles in forum New To JavaReplies: 1Last Post: 02-01-2008, 01:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks