home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / ActiveX / JBrowser / JBrowserOpen.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  2.5 KB  |  106 lines

  1. //////////////////////////////////////////////////////////////////////////
  2. // JBrowserOpen.java
  3. // This is a dialog box which asks the user to enter a URL to open
  4. //
  5. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  6. //////////////////////////////////////////////////////////////////////////
  7.  
  8.  
  9. // standard java
  10. import java.awt.*;
  11. import java.awt.event.*;
  12.  
  13. //
  14. //
  15. // JBrowserOpen
  16. //
  17. //
  18. public class JBrowserOpen extends Dialog implements ActionListener
  19. {
  20.     JBrowser parent;                                                                    // the browser who called this dialog
  21.     TextField urlEdit = new TextField("                                  ");            // the url to go to.
  22.     Button openButton = new Button(" open ");            // open button
  23.     Button cancelButton = new Button(" cancel ");        // cancel button
  24.  
  25.     public JBrowserOpen(JBrowser parent)
  26.     {
  27.         // call the Dialog constructor to create a modal dialog box
  28.         super(parent, "Open URL", true);
  29.  
  30.         this.parent = parent;
  31.  
  32.         // setup the dialog box
  33.         setBackground(Color.lightGray );
  34.         setBounds(200,200,400,400);
  35.         setLayout( new FlowLayout() );
  36.  
  37.         // add a text message
  38.         add( new Label("The URL to open"));
  39.  
  40.         // add a text field
  41.         add( urlEdit);
  42.  
  43.         // add a panel with two buttons
  44.         Panel p2 = new Panel();
  45.         p2.setLayout( new FlowLayout(2) );
  46.         p2.add(openButton);
  47.         p2.add(cancelButton);
  48.         add(p2);
  49.  
  50.         // add event hooks
  51.         urlEdit.addActionListener(this);
  52.         openButton.addActionListener(this);
  53.         cancelButton.addActionListener(this);
  54.         addWindowListener( new JBrowserOpenWindowListener() );
  55.         pack();
  56.         urlEdit.setText("");
  57.         setVisible(true);
  58.     }
  59.  
  60.     /**
  61.      * This method is invoked when an AWT event occurs (i.e. an AWT component
  62.      * fires an action event).
  63.      *
  64.      * @param    ActionEvent        The action event which occurred
  65.      */
  66.     public void actionPerformed(ActionEvent evt)
  67.     {
  68.         Object source = evt.getSource();
  69.  
  70.         if(source == urlEdit)
  71.         {
  72.             dispose();
  73.             parent.navigate(urlEdit.getText() );
  74.         }
  75.         else if(source == cancelButton)
  76.         {
  77.             dispose();
  78.         }
  79.  
  80.         else if (source == openButton)
  81.         {
  82.             dispose();
  83.             parent.navigate(urlEdit.getText() );
  84.         }
  85.  
  86.     }
  87.  
  88.     /**
  89.      * This inner class is to listen to window events
  90.      */
  91.     public class JBrowserOpenWindowListener extends WindowAdapter
  92.     {
  93.         /**
  94.          * This method is invoked when the user clicks on the close window button
  95.          * in the dialog box's window
  96.          *
  97.          * @param    WindowEvent    The event which occurred
  98.          */
  99.         public void windowClosing(WindowEvent evt)
  100.         {
  101.             dispose();
  102.         }
  103.     }
  104.  
  105. }
  106.