• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return a value by firing a JButton event

 
jhon max
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jhon max
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


but I still get a null value

the whole changes I made


 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh my... Is there any simple way to resolve this sir.??
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you should dispose or hide (setVisible(false)) your dialog when you press OK.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic