KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > tools > MessageBox


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: MessageBox.java,v 1.7 2000/10/28 16:55:20 daniela Exp $
8

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 JavaDoc 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 JavaDoc 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 JavaDoc msg ) {
81         new MessageBox( parent, msg, YES | NO );
82         return choice;
83     }
84     
85     
86     public static int OkCancelBox( Frame parent, String JavaDoc msg ) {
87         new MessageBox( parent, msg, OK | CANCEL );
88         return choice;
89     }
90     
91     
92     public static int ConfirmBox( Frame parent, String JavaDoc msg ) {
93         new MessageBox( parent, msg, CONFIRM );
94         return choice;
95     }
96 }
97
Popular Tags