aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes return a value by firing a JButton event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "return a value by firing a JButton event" Watch "return a value by firing a JButton event" New topic
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: 19720
    
  20

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 - OCEEJBD 6
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: 19720
    
  20

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: 19720
    
  20

And you should dispose or hide (setVisible(false)) your dialog when you press OK.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return a value by firing a JButton event