Thread View: borland.public.jbuilder.java.swing
3 messages
3 total messages
Started by Angry Orca
Tue, 17 Aug 2004 23:16
How can I know which button is clicked in JDialog ShowModal
Author: Angry Orca
Date: Tue, 17 Aug 2004 23:16
Date: Tue, 17 Aug 2004 23:16
26 lines
1434 bytes
1434 bytes
Hi, all,
In a programme using swing (homework), I use a JDialog window. There are
two buttons on this dialog window. I want to write the program in this way:
// some thing
JDialog d = new ...
...
d.setModal(true);
d.show();
if (d.close = btnOk){
...
} else if (d.close == btnCancel){
...
}
In fact I want to use this way like in the windows programming:
int i = d.showModal();
if (i == ok){
...
} else if ( i == cancel){
...
}
Please help me. I am a newbie in swing programming.
Thanks a lot.
Re: How can I know which button is clicked in JDialog ShowModal
Author: Tor Iver Wilhelmsen [TeamB]
Date: Wed, 18 Aug 2004 08:10
Date: Wed, 18 Aug 2004 08:10
36 lines
1794 bytes
1794 bytes
Angry Orca <luke@prismtechnologies.com> writes:
> In fact I want to use this way like in the windows programming:
> int i = d.showModal();
> if (i == ok){
> ...
> } else if ( i == cancel){
> ...
> }
Make your own subclass of JDialog that has such a method, and return a
value from it that you test. Preferrably against a constant like an
int, and not against a component. Example:
public class MyDialog extends JDialog {
public static final int OK = 1;
public static final int CANCEL = 2;
int returnValue = 0;
JButton okButton = new JButton();
...
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
returnValue = OK;
hide();
}
}
public int showModal() {
setModal(true);
show();
return returnValue;
}
}
Re: How can I know which button is clicked in JDialog ShowModal
Author: Luke
Date: Wed, 18 Aug 2004 13:04
Date: Wed, 18 Aug 2004 13:04
8 lines
1254 bytes
1254 bytes
> > Make your own subclass of JDialog that has such a method, and return a > value from it that you test. Preferrably against a constant like an > int, and not against a component. Example: Thanks a lot! Cheers
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads