Popup.java

Download Popup.java

 1: // This program creates a blank pop-up window inside a Frame.
 2: // The pop-up window appears and disappears when the user clicks
 3: // the mouse in the main window ("myFrame", not "myWin").
 4: // Written 1999 by Wayne Pollock, Tampa FL USA.
 5: 
 6: import java.awt.*;
 7: import java.awt.event.*;
 8: 
 9: public class Popup
10: {   static Window myWin;
11: 
12:     public static void main ( String [] args )
13:     {   Frame myFrame = new Frame( "Wonder Window!" );
14:         myFrame.setSize( 350, 200 );
15:         myFrame.setBackground( Color.CYAN );
16:         myFrame.setVisible( true );
17: 
18:         myWin = new Window( myFrame );  // A pop-up window
19:         // setBounds() is equal to setSize() and setLocation():
20:         myWin.setBounds( 30, 30, 100, 100 );
21:         myWin.setBackground( Color.BLUE );
22:         myWin.setVisible( true );
23: 
24:         myFrame.addWindowListener( new WindowAdapter()
25:             {   public void windowClosing ( WindowEvent we )
26:                 {   System.exit( 0 );
27:                 }
28:             }
29:         );
30: 
31:         myFrame.addMouseListener( new MouseAdapter ()
32:             {   public void mouseClicked ( MouseEvent e )
33:                 {   myWin.setVisible( ! myWin.isVisible() );
34:                 }
35:             }
36:         );
37:     }
38: }