1   package main;
2   
3   import intellego.Intellego;
4   import util.*;
5   import interfaces.*;
6   import real.*;
7   
8   import java.awt.*;
9   import java.awt.event.*;
10  import javax.swing.*;
11  
12  /**
13  * Providea a general purpose dialog box to display messages from the
14  * system to the user.
15  *
16  * @author Graham Ritchie
17  * @modifyer: Simon Zienkiewicz
18  */
19  class IntellegoDialog extends JDialog implements ActionListener, WindowFocusListener, WindowListener
20  {
21      JLabel message;
22      JButton OK;
23      static int openFrameCount=5;
24      static final int xOffset = 30, yOffset = 30;
25      private boolean exitWin = false;
26  
27      /**
28      * Creates and displays the dialog box
29      *
30      * @param text the message to be displyed to the user
31      */
32      public IntellegoDialog(String text)
33      {
34          openFrameCount++;
35          setSize(600,100);
36          setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
37  
38          this.setDefaultLookAndFeelDecorated(false);
39          this.setUndecorated(true);
40          this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
41  
42          Container c=getContentPane();
43          c.setLayout(new BorderLayout(1,1));
44  
45          Container top=new Container();
46          top.setLayout(new FlowLayout());
47  
48          Container bottom=new Container();
49          bottom.setLayout(new FlowLayout());
50  
51          (OK=new JButton("OK")).addActionListener(this);
52          message=new JLabel(text);
53          message.setForeground(Color.lightGray);
54          OK.setBackground(Color.lightGray);
55          OK.setForeground(Color.DARK_GRAY);
56  
57          top.add("Center",message);
58          bottom.add("Center",OK);
59  
60          c.setBackground(Color.darkGray);
61          c.add("North",top);
62          c.add("South",bottom);
63                  
64          this.addWindowFocusListener(this);
65          this.addWindowListener(this);
66                  
67          show();
68      }
69  
70      /**
71      * Disposes with the dialog box when the user clicks on OK
72      *
73      * @param e the action event
74      */
75      public void actionPerformed(ActionEvent e)
76      {
77              exitWin = true;
78              dispose();
79              openFrameCount--;
80      }
81  
82      public void windowGainedFocus(WindowEvent e) {
83      }
84      
85      public void windowLostFocus(WindowEvent e) {
86          if(exitWin == false){
87              //sound
88              this.getToolkit().beep();
89              this.show();
90          }
91          
92      }
93      
94      public void windowActivated(WindowEvent e) {
95      }
96      
97      public void windowClosed(WindowEvent e) {
98      }
99      
100     public void windowClosing(WindowEvent e) {
101          exitWin = true;
102          dispose();
103     }
104     
105     public void windowDeactivated(WindowEvent e) {
106     }
107     
108     public void windowDeiconified(WindowEvent e) {
109     }
110     
111     public void windowIconified(WindowEvent e) {
112     }
113     
114     public void windowOpened(WindowEvent e) {
115     }    
116 }
117