Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDialog

 
aymane chetibi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I want to create a dialog and then let the user chooses among three options, then return the option choosen to the method that showed the dialog.

I created the dialog, now I don't know how to get back what the use choses
my code looks smthing like that:
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your 3 option are checkbox or radio type?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one of the ways:
include a method in the dialog to return the selection (object, int, whatever).
make the dialog modal, so the method does not return until the dialog closes
[object?] selection = new dialog(name).getSelection();
 
aymane chetibi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got your point. but how can I make the model that way ?
and the options are just buttons!
(should I also, do smthing like that at the end of the action of the buttons: System.exit(1))

thanks!!!

regards,
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the options are just buttons, have you looked at
JOptionPane.showOptionDialog(...)

here's a simple demo
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic