Article View: borland.public.jbuilder.java.swing
Article #998Re: How can I know which button is clicked in JDialog ShowModal
From: 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;
}
}
Technical Details
Message-ID:
<u8yccvpbm.fsf@broadpark.no>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<412291da$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,f4e663468e7be18 X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Sender: Tor Iver Wilhelmsen@TIWILHEL Newsgroups: borland.public.jbuilder.java.swing Subject: Re: How can I know which button is clicked in JDialog ShowModal References: <412291da$1@newsgroups.borland.com> From: tor.iver.wilhelmsen@broadpark.no (Tor Iver Wilhelmsen [TeamB]) Date: 18 Aug 2004 10:10:53 +0200 Message-ID: <u8yccvpbm.fsf@broadpark.no> Lines: 36 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 80.203.79.252 X-Trace: newsgroups.borland.com 1092816424 80.203.79.252 (18 Aug 2004 01:07:04 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail