Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jflight/awt/AlertDialog.java


1   /*
2    * @(#)AlertDialog.java 1.3 98/06/04 SMI
3    *
4    * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
5    *
6    * Sun grants you ("Licensee") a non-exclusive, royalty free, license
7    * to use, modify and redistribute this software in source and binary
8    * code form, provided that i) this copyright notice and license appear
9    * on all copies of the software; and ii) Licensee does not utilize the
10   * software in a manner which is disparaging to Sun.
11   *
12   * This software is provided "AS IS," without a warranty of any kind.
13   * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
14   * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
15   * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
16   * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
17   * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE
18   * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS
19   * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
20   * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
21   * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING
22   * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
23   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
24   *
25   * This software is not designed or intended for use in on-line control
26   * of aircraft, air traffic, aircraft navigation or aircraft
27   * communications; or in the design, construction, operation or
28   * maintenance of any nuclear facility. Licensee represents and
29   * warrants that it will not use or redistribute the Software for such
30   * purposes.
31   */
32  package jflight.awt;
33  
34  import java.awt.*;
35  import java.awt.event.*;
36  
37  
38  /**
39  A single response modal alert dialog. This class is configurable for message
40  and title. The width of the dialog will be longer than the longest message
41  line.  When the OK button is pressed the dialog returns.
42  */
43  public class AlertDialog extends Dialog implements ActionListener {
44  
45      /**
46      Creates a new <code>AlertDialog</code> with three lines of message and
47      a title.
48  
49      @param parent Any Frame.
50      @param title The title to appear in the border of the dialog.
51      @param lineOne The first line of the message in the dialog.
52      @param lineTwo The second line of the message in the dialog.
53      @param lineThree The third line of the message in the dialog.
54      */
55      public AlertDialog(Frame parent, String title, String lineOne,
56                         String lineTwo, String lineThree) {
57  
58          super(parent, title, true);
59  
60          Panel labelPanel = new Panel();
61  
62          labelPanel.setLayout(new GridLayout(3, 1));
63          labelPanel.add(new Label(lineOne, Label.CENTER));
64          labelPanel.add(new Label(lineTwo, Label.CENTER));
65          labelPanel.add(new Label(lineThree, Label.CENTER));
66          add(labelPanel, "Center");
67  
68          Panel  buttonPanel = new Panel();
69          Button okButton    = new Button("OK");
70  
71          okButton.addActionListener(this);
72          buttonPanel.add(okButton);
73          add(buttonPanel, "South");
74  
75          FontMetrics fm    = getFontMetrics(getFont());
76          int width = Math.max(fm.stringWidth(lineOne),
77            Math.max(fm.stringWidth(lineTwo), fm.stringWidth(lineThree)));
78          setSize(width + 40, 150);
79          setLocation(parent.getLocationOnScreen().x + 30,
80            parent.getLocationOnScreen().y + 30);
81          setVisible(true);
82      }
83  
84      /**
85      Handles events from the OK button. When OK is pressed the dialog becomes
86      invisible, disposes of its self, and retruns.
87       *
88       * @param e
89      */
90      public void actionPerformed(ActionEvent e) {
91        setVisible(false);
92        dispose();
93      }
94  }
95