Results 1 to 7 of 7

Thread: retreiving text

  1. #1
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default retreiving text

    I am prompting a user for a response in my program. here is my code that puts in the prompt:

    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.");
    and then the method:

    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();
    	}
    i tried adding this inside the actionPerformed:

    Java Code:
    userInput = uI.getText();
    But i got this error:
    Java Code:
    Cannot refer to a non-final variable userInput inside an inner class defined in a different method
    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...
    Last edited by droidus; 01-24-2012 at 03:41 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default 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!

  3. #3
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default 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.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default 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!

  5. #5
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default 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?

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: retreiving text

    Quote Originally Posted by droidus View Post
    hm, would there be a better way about designing this program that you would recommend? or is the dialog definitely the way to go?
    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!

  7. #7
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default 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

  1. Retreiving value from a for-loop
    By BariMutation in forum New To Java
    Replies: 3
    Last Post: 10-12-2010, 10:24 PM
  2. Help in retreiving database data using a loop
    By danpj in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 07-17-2009, 08:49 AM
  3. Retreiving of mail body using mail number
    By chandu.v09 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-13-2008, 02:25 PM
  4. Retreiving list of keys from Map with certan value
    By desmond5 in forum New To Java
    Replies: 1
    Last Post: 03-06-2008, 08:10 PM
  5. Replies: 1
    Last Post: 02-01-2008, 01:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •