home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Java / Creator Changer / Creator Changer Project / Source / AboutCCDialog.java next >
Encoding:
Java Source  |  2000-09-28  |  4.0 KB  |  164 lines  |  [TEXT/SNJ2]

  1. import java.awt.*;
  2. import java.awt.event.KeyEvent;
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.net.URL;
  7.  
  8. public class AboutCCDialog extends Dialog
  9. {
  10.     public AboutCCDialog(Frame parent)
  11.     {
  12.         super(parent, true);
  13.  
  14.         // This code is automatically generated by Visual Cafe when you add
  15.         // components to the visual environment. It instantiates and initializes
  16.         // the components. To modify the code, only use code syntax that matches
  17.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  18.         // parse your Java file into its visual environment.
  19.         //{{INIT_CONTROLS
  20.         GridBagLayout gridBagLayout;
  21.         gridBagLayout = new GridBagLayout();
  22.         setLayout(gridBagLayout);
  23.         setVisible(false);
  24.         setSize(440,260);
  25.         setBackground(new Color(-1644826));
  26.  
  27.         defaultBorder1 = new DefaultBorder();
  28.         defaultBorder1.setBounds(178,227,64,26);
  29.         GridBagConstraints gbc;
  30.         gbc = new GridBagConstraints();
  31.         gbc.gridx = 0;
  32.         gbc.gridy = 1;
  33.         gbc.fill = GridBagConstraints.NONE;
  34.         gbc.insets = new Insets(0,0,10,0);
  35.         ((GridBagLayout)getLayout()).setConstraints(defaultBorder1, gbc);
  36.         okButton = new java.awt.Button();
  37.         okButton.setLabel("OK");
  38.         okButton.setBounds(3,3,58,20);
  39.         defaultBorder1.add(okButton);
  40.         add(defaultBorder1);
  41.         textArea1 = new java.awt.TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
  42.         textArea1.setEditable(false);
  43.         textArea1.setText("");
  44.         textArea1.setFont(new Font("SansSerif", Font.PLAIN, 9));
  45.         textArea1.setBackground(new Color(16777215));
  46.         gbc = new GridBagConstraints();
  47.         gbc.gridx = 0;
  48.         gbc.gridy = 0;
  49.         gbc.weightx = 0.5;
  50.         gbc.weighty = 0.5;
  51.         gbc.fill = GridBagConstraints.BOTH;
  52.         gbc.insets = new Insets(10,10,10,10);
  53.         ((GridBagLayout)getLayout()).setConstraints(textArea1, gbc);
  54.         add(textArea1);
  55.         setTitle("About...");
  56.         setResizable(false);
  57.         //}}
  58.  
  59.         //{{REGISTER_LISTENERS
  60.         SymWindow aSymWindow = new SymWindow();
  61.         this.addWindowListener(aSymWindow);
  62.         SymAction lSymAction = new SymAction();
  63.         okButton.addActionListener(lSymAction);
  64.         SymKey aSymKey = new SymKey();
  65.         textArea1.addKeyListener(aSymKey);
  66.         okButton.addKeyListener(aSymKey);
  67.         this.addKeyListener(aSymKey);
  68.         //}}
  69.         
  70.         try
  71.         {
  72.             String contents = Util.readTextResourceFile("files/About.txt", this);
  73.             textArea1.setText(contents);
  74.         }
  75.         catch (FileNotFoundException exc)
  76.         {
  77.             System.err.println(exc);
  78.         }
  79.         catch (IOException exc)
  80.         {
  81.             System.err.println(exc);
  82.         }
  83.     }
  84.     
  85.     /**
  86.      * Shows or hides the component depending on the boolean flag b.
  87.      * @paramLabel b  if true, show the component; otherwise, hide the component.
  88.      * @see java.awt.Component#isVisible
  89.      */
  90.     public void setVisible(boolean b)
  91.     {
  92.         if(b)
  93.         {
  94.             Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
  95.             Dimension dSize = getSize();
  96.     
  97.             setLocation((sSize.width - dSize.width) >> 1, (int)(0.33333333 * sSize.height));
  98.         }
  99.         super.setVisible(b);
  100.     }
  101.  
  102.     public void update(Graphics g)
  103.     {
  104.         paint(g);
  105.     }
  106.  
  107.     public void close()
  108.     {
  109.         // Hide the Dialog
  110.         setVisible(false);
  111.         dispose();
  112.     }
  113.  
  114.     //{{DECLARE_CONTROLS
  115.     java.awt.Button okButton;
  116.     java.awt.TextArea textArea1;
  117.     DefaultBorder defaultBorder1;
  118.     //}}
  119.  
  120.     class SymWindow extends java.awt.event.WindowAdapter
  121.     {
  122.         public void windowClosing(java.awt.event.WindowEvent event)
  123.         {
  124.             Object object = event.getSource();
  125.             if (object == AboutCCDialog.this)
  126.                 AboutCCDialog_WindowClosing(event);
  127.         }
  128.     }
  129.     
  130.     void AboutCCDialog_WindowClosing(java.awt.event.WindowEvent event)
  131.     {
  132.         close();
  133.     }
  134.  
  135.     class SymAction implements java.awt.event.ActionListener
  136.     {
  137.         public void actionPerformed(java.awt.event.ActionEvent event)
  138.         {
  139.             Object object = event.getSource();
  140.             if (object == okButton)
  141.                 okButton_ActionPerformed(event);
  142.         }
  143.     }
  144.  
  145.     void okButton_ActionPerformed(java.awt.event.ActionEvent event)
  146.     {
  147.         close();
  148.     }
  149.  
  150.     class SymKey extends java.awt.event.KeyAdapter
  151.     {
  152.         public void keyPressed(java.awt.event.KeyEvent event)
  153.         {
  154.             handleKeyPressed(event);
  155.         }
  156.     }
  157.  
  158.     void handleKeyPressed(java.awt.event.KeyEvent event)
  159.     {
  160.         if (event.getKeyCode() == KeyEvent.VK_ENTER)
  161.             close();
  162.     }
  163. }
  164.