OverlapHeavy.java

Download OverlapHeavy.java

 1: // This class shows what happens when you have two heavyweight
 2: // components that overlap.  (The one added last ends up on
 3: // the bottom, not the top as you might expect.)
 4: //
 5: // Written 11/2009 by Wayne Pollock, Tampa Florida USA
 6: 
 7: import java.awt.*;
 8: import java.awt.event.*;
 9: 
10: public class OverlapHeavy extends Frame
11: {
12:    public static void main ( String [] args )
13:    {
14:       Frame frame = new OverlapHeavy();
15:       frame.setVisible( true );
16:       frame.requestFocus();
17:    }
18: 
19:    public OverlapHeavy ()
20:    {
21:       // Set Frame properties:
22:       setLayout( null );  // Don't use any layout manager.
23:       setTitle( "Overlapping heavyweight components");
24:       setSize( 470, 220 );
25: 
26:       // Create Components and adjust their properties:
27: 
28:       Button b1 = new Button("Added First");
29:       Button b2 = new Button("Added Second");
30: 
31:       b1.setBackground( Color.GREEN );
32:       b1.setBounds( 40, 50, 100, 70 );  // x, y, width, height
33: 
34:       b2.setBackground( Color.CYAN );
35:       b2.setBounds( 100, 85, 100, 70 );
36: 
37:       // Add components and hook up event handling:
38:       add( b1 );
39:       add( b2 );
40: 
41:       addWindowListener( new WindowAdapter()
42:          {   public void windowClosing ( WindowEvent we )
43:              {   System.exit( 0 );
44:              }
45:          }
46:       );
47:    }
48: }