Re: simple input box ok button?
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Wed, 31 Aug 2005 14:51:30 GMT
"6e" <aotemp@xxxxxxxxxxx> wrote in message
news:1125499360.015637.256690@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> Im trying to do something simple, but for some reason Im having trouble
> with this Java concept..
>
> I am creating a small pop-up input box, and I want the user to be able
> to insert text into a JTextField, and hit "ok" to return close the
> screen AND return the text in JTextField.
>
> So I know I need to handle actionperformed to make this happen, but I
> cannot assign the text this way... The only thing Ive thought of is
> creating a global variable for this purpose, but it seems like overkill
> for a such a simple routine...
>
> Code is below, I would appreciate some advice. Thanks!
I've come across the same problem and I don't know of an elegant
solution for it. Anyway, here's what I usually do:
You have code that actually makes the pop-up show up right? And that's
the code that needs access to the value in the JTextField, right? Well, the
pop-up itself is an object, right? So add a method in the pop-up class that
returns the value in the JTextField. The calling code then creates and shows
the pop up box as usual, and then waits for the "ok" button to be pressed.
It then calls the method you added to get the value that was in the
JTextField.
- Oliver
.
- References:
- simple input box ok button?
- From: 6e
- simple input box ok button?
- Prev by Date: simple input box ok button?
- Next by Date: Re: Method chaining with generics
- Previous by thread: simple input box ok button?
- Next by thread: Re: simple input box ok button?
- Index(es):