home *** CD-ROM | disk | FTP | other *** search
- /*
- This simple extension of the java.awt.Frame class
- contains all the elements necessary to act as the
- main window of an application.
- */
-
- import java.awt.*;
-
- public class Frame1 extends Frame
- {
- public Frame1()
- {
- // This code is automatically generated by Visual Cafe when you add
- // components to the visual environment. It instantiates and initializes
- // the components. To modify the code, only use code syntax that matches
- // what Visual Cafe can generate, or Visual Cafe may be unable to back
- // parse your Java file into its visual environment.
-
- //{{INIT_CONTROLS
- setLayout(null);
- setSize(405,305);
- openFileDialog1 = new java.awt.FileDialog(this, "Open",FileDialog.LOAD);
- //$$ openFileDialog1.move(40,277);
- setTitle("A Basic Application");
- //}}
-
- //{{INIT_MENUS
- mainMenuBar = new java.awt.MenuBar();
-
- menu1 = new java.awt.Menu("File");
- miNew = new java.awt.MenuItem("New");
- miNew.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_N,false));
- menu1.add(miNew);
- miOpen = new java.awt.MenuItem("Open...");
- miOpen.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_O,false));
- menu1.add(miOpen);
- miSave = new java.awt.MenuItem("Save");
- miSave.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_S,false));
- menu1.add(miSave);
- miSaveAs = new java.awt.MenuItem("Save As...");
- menu1.add(miSaveAs);
- menu1.addSeparator();
- miExit = new java.awt.MenuItem("Exit");
- menu1.add(miExit);
- mainMenuBar.add(menu1);
-
- menu2 = new java.awt.Menu("Edit");
- miCut = new java.awt.MenuItem("Cut");
- miCut.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_X,false));
- menu2.add(miCut);
- miCopy = new java.awt.MenuItem("Copy");
- miCopy.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_C,false));
- menu2.add(miCopy);
- miPaste = new java.awt.MenuItem("Paste");
- miPaste.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_V,false));
- menu2.add(miPaste);
- mainMenuBar.add(menu2);
-
- menu3 = new java.awt.Menu("Help");
- mainMenuBar.setHelpMenu(menu3);
- miAbout = new java.awt.MenuItem("About..");
- menu3.add(miAbout);
- mainMenuBar.add(menu3);
- setMenuBar(mainMenuBar);
- //$$ mainMenuBar.move(4,277);
- //}}
-
- //{{REGISTER_LISTENERS
- SymWindow aSymWindow = new SymWindow();
- this.addWindowListener(aSymWindow);
- SymAction lSymAction = new SymAction();
- miOpen.addActionListener(lSymAction);
- miAbout.addActionListener(lSymAction);
- miExit.addActionListener(lSymAction);
- //}}
- }
-
- public Frame1(String title)
- {
- this();
- setTitle(title);
- }
-
- /**
- * Shows or hides the component depending on the boolean flag b.
- * @param b if true, show the component; otherwise, hide the component.
- * @see java.awt.Component#isVisible
- */
- public void setVisible(boolean b)
- {
- if(b)
- {
- setLocation(50, 50);
- }
- super.setVisible(b);
- }
-
- static public void main(String args[])
- {
- (new Frame1()).setVisible(true);
- }
-
- public void addNotify()
- {
- // Record the size of the window prior to calling parents addNotify.
- Dimension d = getSize();
-
- super.addNotify();
-
- if (fComponentsAdjusted)
- return;
-
- // Adjust components according to the insets
- setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
- Component components[] = getComponents();
- for (int i = 0; i < components.length; i++)
- {
- Point p = components[i].getLocation();
- p.translate(insets().left, insets().top);
- components[i].setLocation(p);
- }
- fComponentsAdjusted = true;
- }
-
- // Used for addNotify check.
- boolean fComponentsAdjusted = false;
-
- //{{DECLARE_CONTROLS
- java.awt.FileDialog openFileDialog1;
- //}}
-
- //{{DECLARE_MENUS
- java.awt.MenuBar mainMenuBar;
- java.awt.Menu menu1;
- java.awt.MenuItem miNew;
- java.awt.MenuItem miOpen;
- java.awt.MenuItem miSave;
- java.awt.MenuItem miSaveAs;
- java.awt.MenuItem miExit;
- java.awt.Menu menu2;
- java.awt.MenuItem miCut;
- java.awt.MenuItem miCopy;
- java.awt.MenuItem miPaste;
- java.awt.Menu menu3;
- java.awt.MenuItem miAbout;
- //}}
-
- class SymWindow extends java.awt.event.WindowAdapter
- {
- public void windowClosing(java.awt.event.WindowEvent event)
- {
- Object object = event.getSource();
- if (object == Frame1.this)
- Frame1_WindowClosing(event);
- }
- }
-
- void Frame1_WindowClosing(java.awt.event.WindowEvent event)
- {
- setVisible(false); // hide the Frame
- dispose(); // free the system resources
- System.exit(0); // close the application
- }
-
- class SymAction implements java.awt.event.ActionListener
- {
- public void actionPerformed(java.awt.event.ActionEvent event)
- {
- Object object = event.getSource();
- if (object == miOpen)
- miOpen_Action(event);
- else if (object == miAbout)
- miAbout_Action(event);
- else if (object == miExit)
- miExit_Action(event);
- }
- }
-
- void miAbout_Action(java.awt.event.ActionEvent event)
- {
- //{{CONNECTION
- // Action from About Create and show as modal
- (new AboutDialog(this, true)).setVisible(true);
- //}}
- }
-
- void miExit_Action(java.awt.event.ActionEvent event)
- {
- //{{CONNECTION
- // Action from Exit Create and show as modal
- (new QuitDialog(this, true)).setVisible(true);
- //}}
- }
-
- void miOpen_Action(java.awt.event.ActionEvent event)
- {
- //{{CONNECTION
- // Action from Open... Show the OpenFileDialog
- int defMode = openFileDialog1.getMode();
- String defTitle = openFileDialog1.getTitle();
- String defDirectory = openFileDialog1.getDirectory();
- String defFile = openFileDialog1.getFile();
-
- openFileDialog1 = new java.awt.FileDialog(this, defTitle, defMode);
- openFileDialog1.setDirectory(defDirectory);
- openFileDialog1.setFile(defFile);
- openFileDialog1.setVisible(true);
- //}}
- }
- }
-
-