///////////////////////////////////////////////////////// // Module MyFrame.java // Version 1.04 // Language Java // Author Sudhakar Chandrasekaran (thaths@netscape.com) // History Last Updated 12/4/97 // 05/17/97 House cleaning // 05/16/97 Dramatic redesign based on vectors and crawlers // REmoved the search() method // 04/20/97 version ++ // Added brief help // 12/04/97 Added MenuBar and menu items. // // Legalese // Copyright (C) 1996-1997 Sudhakar Chandrasekharan // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2 of the license, or (at your // option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. Writers of free software // cannot afford getting sued! // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 675 Mass Ave., Cambridge, MA 02139, USA. // // Sudhakar "Thaths" Chandrasekharan, 20 Apr 1996. //////////////////////////////////////////////////////// // First import all the standard packages that we need import java.awt.*; // Import custom packages import SearchForText; class MyFrame extends Frame { // Data Members ClientSearch clientSearch; // The three panels inside this Frame. SearchPanel searchPanel; OptionsPanel optionsPanel; ResultPanel resultPanel; // The number of the page being currently searched // This should be lesser than clientSearch.totalPages int currentPageNumber; // Constructor MyFrame(ClientSearch cs, Frame frame, String title) { super(title); clientSearch = cs; // File menu and it's elements Menu fileMenu = new Menu("File"); fileMenu.addSeparator(); fileMenu.add("Close"); // Help menu and it's elements Menu helpMenu = new Menu("Help"); helpMenu.add("Help on searching..."); helpMenu.addSeparator(); helpMenu.add("About..."); // The menu bar at the top MenuBar menuBar = new MenuBar(); menuBar.add(fileMenu); menuBar.add(helpMenu); menuBar.setHelpMenu(helpMenu); // Get the bg and fg colors from the applet and // set the bg and fg of this frame to be the same setBackground(cs.getBackground()); setForeground(cs.getForeground()); // Add the menubar and it's menu items to this frame setMenuBar(menuBar); // show(); // Create a GridBagLayout and its GridBagConstraints // and start adding the panels one by one GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); // Specify the constraints for the searchPanel c.insets = this.insets(); // insets for panel same as for Frame c.ipadx=2; // padding for panel c.ipady=2; c.gridwidth=GridBagConstraints.REMAINDER; // Last Element in its row c.fill=GridBagConstraints.NONE; // Don't fill the whole row c.anchor = GridBagConstraints.CENTER; // Center the element in row // Create an instance of searchPanel and add it searchPanel = new SearchPanel(this); gridbag.setConstraints(searchPanel, c); add(searchPanel); // Constaints of optionsPanel same as those of searchPanel // Create an instance of optionsPanel and add it optionsPanel = new OptionsPanel(this); gridbag.setConstraints(optionsPanel,c); add(optionsPanel); // Constraints of resultsPanel almost the same as // those of optionsPanel c.gridheight = GridBagConstraints.REMAINDER; // Last column // Create an instance of resultsPanel and add it resultPanel = new ResultPanel(this); gridbag.setConstraints(resultPanel, c); add(resultPanel); } // Start painting the chrome public void paint(Graphics g) { Dimension d = size(); g.setColor(new Color(0,0,255)); // Blue // Draw a nice 3-D box around the applet g.draw3DRect(0,0,d.width-2,d.height-2,true); g.draw3DRect(2,2,d.width-5,d.height-5,false); } // The padding for this frame public Insets insets() { return new Insets(3,3,3,3); } // Event Handler // If 'Close' selected, hide() this frame // If 'Help on searching...' selected, create the helpDialog // If 'About' selected, crate the aboutDialog // The three panels will take care of their own events public boolean action(Event event, Object onWhat) { if (event.target instanceof MenuItem) { String label = (String) onWhat; if (label.equals("Close")) { hide(); } else if (label.equals("Help on searching...")) { HelpDialog helpDialog = new HelpDialog(this); } else if (label.equals("About...")) { AboutDialog aboutDialog = new AboutDialog(this); } return true; } else if (event.id == Event.WINDOW_DESTROY) { hide(); return true; // this.dispose(); } else { return super.handleEvent(event); } } }