home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / promain.bin / DBVPO.DLL / SOURCE / SIMPLEAPP < prev    next >
Text File  |  1998-03-18  |  6KB  |  212 lines

  1. /*
  2.     This simple extension of the java.awt.Frame class
  3.     contains all the elements necessary to act as the
  4.     main window of an application.
  5.  */
  6.  
  7. import java.awt.*;
  8.  
  9. public class Frame1 extends Frame
  10. {
  11.     public Frame1()
  12.     {
  13.         // This code is automatically generated by Visual Cafe when you add
  14.         // components to the visual environment. It instantiates and initializes
  15.         // the components. To modify the code, only use code syntax that matches
  16.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  17.         // parse your Java file into its visual environment.
  18.         
  19.         //{{INIT_CONTROLS
  20.         setLayout(null);
  21.         setSize(405,305);
  22.         openFileDialog1 = new java.awt.FileDialog(this, "Open",FileDialog.LOAD);
  23.         //$$ openFileDialog1.move(40,277);
  24.         setTitle("A Basic Application");
  25.         //}}
  26.         
  27.         //{{INIT_MENUS
  28.         mainMenuBar = new java.awt.MenuBar();
  29.         
  30.         menu1 = new java.awt.Menu("File");
  31.         miNew = new java.awt.MenuItem("New");
  32.         miNew.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_N,false));
  33.         menu1.add(miNew);
  34.         miOpen = new java.awt.MenuItem("Open...");
  35.         miOpen.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_O,false));
  36.         menu1.add(miOpen);
  37.         miSave = new java.awt.MenuItem("Save");
  38.         miSave.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_S,false));
  39.         menu1.add(miSave);
  40.         miSaveAs = new java.awt.MenuItem("Save As...");
  41.         menu1.add(miSaveAs);
  42.         menu1.addSeparator();
  43.         miExit = new java.awt.MenuItem("Exit");
  44.         menu1.add(miExit);
  45.         mainMenuBar.add(menu1);
  46.         
  47.         menu2 = new java.awt.Menu("Edit");
  48.         miCut = new java.awt.MenuItem("Cut");
  49.         miCut.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_X,false));
  50.         menu2.add(miCut);
  51.         miCopy = new java.awt.MenuItem("Copy");
  52.         miCopy.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_C,false));
  53.         menu2.add(miCopy);
  54.         miPaste = new java.awt.MenuItem("Paste");
  55.         miPaste.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_V,false));
  56.         menu2.add(miPaste);
  57.         mainMenuBar.add(menu2);
  58.         
  59.         menu3 = new java.awt.Menu("Help");
  60.         mainMenuBar.setHelpMenu(menu3);
  61.         miAbout = new java.awt.MenuItem("About..");
  62.         menu3.add(miAbout);
  63.         mainMenuBar.add(menu3);
  64.         setMenuBar(mainMenuBar);
  65.         //$$ mainMenuBar.move(4,277);
  66.         //}}
  67.         
  68.         //{{REGISTER_LISTENERS
  69.         SymWindow aSymWindow = new SymWindow();
  70.         this.addWindowListener(aSymWindow);
  71.         SymAction lSymAction = new SymAction();
  72.         miOpen.addActionListener(lSymAction);
  73.         miAbout.addActionListener(lSymAction);
  74.         miExit.addActionListener(lSymAction);
  75.         //}}
  76.     }
  77.     
  78.     public Frame1(String title)
  79.     {
  80.         this();
  81.         setTitle(title);
  82.     }
  83.     
  84.     /**
  85.      * Shows or hides the component depending on the boolean flag b.
  86.      * @param b  if true, show the component; otherwise, hide the component.
  87.      * @see java.awt.Component#isVisible
  88.      */
  89.     public void setVisible(boolean b)
  90.     {
  91.         if(b)
  92.         {
  93.             setLocation(50, 50);
  94.         }    
  95.         super.setVisible(b);
  96.     }
  97.     
  98.     static public void main(String args[])
  99.     {
  100.         (new Frame1()).setVisible(true);
  101.     }
  102.     
  103.     public void addNotify()
  104.     {
  105.         // Record the size of the window prior to calling parents addNotify.
  106.         Dimension d = getSize();
  107.         
  108.         super.addNotify();
  109.     
  110.         if (fComponentsAdjusted)
  111.             return;
  112.     
  113.         // Adjust components according to the insets
  114.         setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
  115.         Component components[] = getComponents();
  116.         for (int i = 0; i < components.length; i++)
  117.         {
  118.             Point p = components[i].getLocation();
  119.             p.translate(insets().left, insets().top);
  120.             components[i].setLocation(p);
  121.         }
  122.         fComponentsAdjusted = true;
  123.     }
  124.     
  125.     // Used for addNotify check.
  126.     boolean fComponentsAdjusted = false;
  127.     
  128.     //{{DECLARE_CONTROLS
  129.     java.awt.FileDialog openFileDialog1;
  130.     //}}
  131.     
  132.     //{{DECLARE_MENUS
  133.     java.awt.MenuBar mainMenuBar;
  134.     java.awt.Menu menu1;
  135.     java.awt.MenuItem miNew;
  136.     java.awt.MenuItem miOpen;
  137.     java.awt.MenuItem miSave;
  138.     java.awt.MenuItem miSaveAs;
  139.     java.awt.MenuItem miExit;
  140.     java.awt.Menu menu2;
  141.     java.awt.MenuItem miCut;
  142.     java.awt.MenuItem miCopy;
  143.     java.awt.MenuItem miPaste;
  144.     java.awt.Menu menu3;
  145.     java.awt.MenuItem miAbout;
  146.     //}}
  147.     
  148.     class SymWindow extends java.awt.event.WindowAdapter
  149.     {
  150.         public void windowClosing(java.awt.event.WindowEvent event)
  151.         {
  152.             Object object = event.getSource();
  153.             if (object == Frame1.this)
  154.                 Frame1_WindowClosing(event);
  155.         }
  156.     }
  157.     
  158.     void Frame1_WindowClosing(java.awt.event.WindowEvent event)
  159.     {
  160.         setVisible(false);    // hide the Frame
  161.         dispose();            // free the system resources
  162.         System.exit(0);        // close the application
  163.     }
  164.     
  165.     class SymAction implements java.awt.event.ActionListener
  166.     {
  167.         public void actionPerformed(java.awt.event.ActionEvent event)
  168.         {
  169.             Object object = event.getSource();
  170.             if (object == miOpen)
  171.                 miOpen_Action(event);
  172.             else if (object == miAbout)
  173.                 miAbout_Action(event);
  174.             else if (object == miExit)
  175.                 miExit_Action(event);
  176.         }
  177.     }
  178.     
  179.     void miAbout_Action(java.awt.event.ActionEvent event)
  180.     {
  181.         //{{CONNECTION
  182.         // Action from About Create and show as modal
  183.         (new AboutDialog(this, true)).setVisible(true);
  184.         //}}
  185.     }
  186.     
  187.     void miExit_Action(java.awt.event.ActionEvent event)
  188.     {
  189.         //{{CONNECTION
  190.         // Action from Exit Create and show as modal
  191.         (new QuitDialog(this, true)).setVisible(true);
  192.         //}}
  193.     }
  194.     
  195.     void miOpen_Action(java.awt.event.ActionEvent event)
  196.     {
  197.         //{{CONNECTION
  198.         // Action from Open... Show the OpenFileDialog
  199.         int        defMode            = openFileDialog1.getMode();
  200.         String    defTitle        = openFileDialog1.getTitle();
  201.         String defDirectory    = openFileDialog1.getDirectory();
  202.         String defFile            = openFileDialog1.getFile();
  203.  
  204.         openFileDialog1 = new java.awt.FileDialog(this, defTitle, defMode);
  205.         openFileDialog1.setDirectory(defDirectory);
  206.         openFileDialog1.setFile(defFile);
  207.         openFileDialog1.setVisible(true);
  208.         //}}
  209.     }
  210. }
  211.  
  212.