1 9 package org.ozoneDB.tools; 10 11 import java.awt.*; 12 import java.awt.event.*; 13 14 15 public class MessageBox extends Dialog { 16 public static int YES = 1; 17 public static int NO = 2; 18 public static int CANCEL = 4; 19 public static int OK = 8; 20 public static int CONFIRM = 16; 21 static int choice; 22 23 24 class MBButton extends Button implements ActionListener { 25 int kind; 26 27 28 public MBButton( String title, int _kind ) { 29 super( title ); 30 kind = _kind; 31 addActionListener( this ); 32 } 33 34 35 public void actionPerformed( ActionEvent e ) { 36 ((MessageBox)getParent()).choice = kind; 37 ((MessageBox)getParent()).close(); 38 } 39 } 40 41 42 MessageBox( Frame parent, String msg, int buttons ) { 43 super( parent, true ); 44 setLayout( new GridBagLayout() ); 45 GridBagConstraints c = new GridBagConstraints(); 46 c.weightx = 1.0; 47 c.weighty = 1.0; 48 c.fill = GridBagConstraints.NONE; 49 c.anchor = GridBagConstraints.CENTER; 50 c.gridwidth = GridBagConstraints.REMAINDER; 51 add( new Label( msg ), c ); 52 c.fill = GridBagConstraints.BOTH; 53 c.gridwidth = GridBagConstraints.RELATIVE; 54 if ((buttons & YES) != 0) { 55 add( new MBButton( "YES", YES ), c ); 56 } 57 if ((buttons & NO) != 0) { 58 add( new MBButton( "NO", NO ), c ); 59 } 60 if ((buttons & CANCEL) != 0) { 61 add( new MBButton( "CANCEL", CANCEL ), c ); 62 } 63 if ((buttons & OK) != 0) { 64 add( new MBButton( "OK", OK ), c ); 65 } 66 if ((buttons & CONFIRM) != 0) { 67 add( new MBButton( "CONFIRM", CONFIRM ), c ); 68 } 69 setSize( 20 + msg.length() * 7, 80 ); 70 setLocation( 200, 200 ); 71 show(); 72 } 73 74 75 public void close() { 76 setVisible( false ); 77 } 78 79 80 public static int YesNoBox( Frame parent, String msg ) { 81 new MessageBox( parent, msg, YES | NO ); 82 return choice; 83 } 84 85 86 public static int OkCancelBox( Frame parent, String msg ) { 87 new MessageBox( parent, msg, OK | CANCEL ); 88 return choice; 89 } 90 91 92 public static int ConfirmBox( Frame parent, String msg ) { 93 new MessageBox( parent, msg, CONFIRM ); 94 return choice; 95 } 96 } 97 | Popular Tags |