| Author |
return a value by firing a JButton event
|
jhon max
Ranch Hand
Joined: Jan 06, 2010
Posts: 45
|
|
I have a class here that I want to act just like a JOptionPane..
but Im stuck with returning a value.. anyway I left some of the method as void to be easily compiled, but lets assume that it returns a String value...
what I want is if I press the button it will return a value from another class that calls that method... please I need help ..
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
1) Give the Popup instance a value defaulting to null:
2) Set this value when you press OK
3) Returns this value from the static method: Because you initialize it to null and only set it when OK is pressed the popTheInput method will return null if the user clicked Cancel or pressed the little X.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
jhon max
Ranch Hand
Joined: Jan 06, 2010
Posts: 45
|
|
but I still get a null value
the whole changes I made
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
That's because your dialog is not a modal dialog, and it does not block the event dispatcher thread. Of course in your small example, it doesn't block the main thread either, which it never will because the main thread and the event dispatcher thread are always separate from the moment you realize your user interface.
|
 |
jhon max
Ranch Hand
Joined: Jan 06, 2010
Posts: 45
|
|
oh my... Is there any simple way to resolve this sir.??
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
jhon max wrote:oh my... Is there any simple way to resolve this sir.??
um,... make it a modal dialog? The JDialog API will show you how.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
And you should dispose or hide (setVisible(false)) your dialog when you press OK.
|
 |
 |
|
|
subject: return a value by firing a JButton event
|
|
|