Skip to content
Snippets Groups Projects
Commit b22bf416 authored by tjc's avatar tjc
Browse files

use JOptionPane

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@9029 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent c7882d96
No related branches found
No related tags found
No related merge requests found
...@@ -20,27 +20,28 @@ ...@@ -20,27 +20,28 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/YesNoDialog.java,v 1.1 2004-06-09 09:48:01 tjc Exp $ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/YesNoDialog.java,v 1.2 2008-10-15 13:45:58 tjc Exp $
*/ */
package uk.ac.sanger.artemis.components; package uk.ac.sanger.artemis.components;
import uk.ac.sanger.artemis.Options; import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/** /**
* A popup dialog box that displays a message and then waits for the to press * A popup dialog box that displays a message and then waits for the to press
* yes or no. * yes or no.
* *
* @author Kim Rutherford * @author Kim Rutherford
* @version $Id: YesNoDialog.java,v 1.1 2004-06-09 09:48:01 tjc Exp $ * @version $Id: YesNoDialog.java,v 1.2 2008-10-15 13:45:58 tjc Exp $
**/ **/
public class YesNoDialog extends JDialog { public class YesNoDialog
{
private JFrame parent;
private String title;
private String message;
/** /**
* Create a new YesNoDialog component. The constructor does not show () * Create a new YesNoDialog component. The constructor does not show ()
* the dialog, call getResult () to do that. * the dialog, call getResult () to do that.
...@@ -48,37 +49,11 @@ public class YesNoDialog extends JDialog { ...@@ -48,37 +49,11 @@ public class YesNoDialog extends JDialog {
* @param title The title of the new dialog JFrame. * @param title The title of the new dialog JFrame.
* @param message The message to display in the JDialog. * @param message The message to display in the JDialog.
**/ **/
public YesNoDialog (JFrame parent, String title, String message) { public YesNoDialog (JFrame parent, String title, String message)
super (parent, message, true); {
this.parent = parent;
getContentPane ().add (new JLabel (message), "North"); this.title = title;
this.message = message;
final JPanel panel = new JPanel ();
panel.add (yes_button);
yes_button.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
button_result = true;
setVisible (false);
YesNoDialog.this.dispose ();
}
});
panel.add (no_button);
no_button.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
button_result = false;
setVisible (false);
YesNoDialog.this.dispose ();
}
});
getContentPane ().add (panel, "South");
pack ();
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
setLocation (new Point ((screen.width - getSize ().width) / 2,
(screen.height - getSize ().height) / 2));
} }
/** /**
...@@ -88,8 +63,9 @@ public class YesNoDialog extends JDialog { ...@@ -88,8 +63,9 @@ public class YesNoDialog extends JDialog {
* @param message The message to display in the JDialog and to uise as the * @param message The message to display in the JDialog and to uise as the
* title string. * title string.
**/ **/
public YesNoDialog (JFrame parent, String message) { public YesNoDialog (JFrame parent, String message)
this (parent, message, message); {
this (parent, null, message);
} }
/** /**
...@@ -97,19 +73,14 @@ public class YesNoDialog extends JDialog { ...@@ -97,19 +73,14 @@ public class YesNoDialog extends JDialog {
* press the Yes button or the No button. * press the Yes button or the No button.
* @return true is the user pressed Yes, false otherwise. * @return true is the user pressed Yes, false otherwise.
**/ **/
public boolean getResult () { protected boolean getResult ()
setVisible (true); {
int result = JOptionPane.showConfirmDialog(
return button_result; parent, message, title,
JOptionPane.YES_NO_OPTION);
if(result == JOptionPane.YES_OPTION)
return true;
return false;
} }
final JButton yes_button = new JButton ("Yes");
final JButton no_button = new JButton ("No");
/**
* Set by the yes and no button action listeners and read by getResult ().
**/
boolean button_result;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment