Source of VisibilityDemo.java


  1: //VisibilityDemo.java
  2: 
  3: import javax.swing.*;
  4: import java.awt.*;
  5: import java.awt.event.*;
  6: 
  7: /**
  8:  Simple demonstration of changing visibility in an Applet.
  9: */
 10: public class VisibilityDemo extends JApplet implements ActionListener
 11: {
 12:     private JLabel response;
 13:     private Container contentPane;
 14: 
 15:     public void init( )
 16:     {
 17:         contentPane = getContentPane( );
 18:         contentPane.setBackground(Color.WHITE);
 19: 
 20:         //Program button:
 21:         JButton aButton = new JButton("Push me!");
 22:         aButton.addActionListener(this);
 23: 
 24:         //Program label:
 25:         response = new JLabel("Thanks. That felt good!");
 26:         ImageIcon smileyFaceIcon = new ImageIcon("smiley.gif");
 27:         response.setIcon(smileyFaceIcon);
 28:         response.setVisible(false);
 29: 
 30:         //Add button:
 31:         contentPane.setLayout(new FlowLayout( ));
 32:         contentPane.add(aButton);
 33: 
 34:         //Add label
 35:         contentPane.add(response);
 36: 
 37:     }
 38: 
 39:     public void actionPerformed(ActionEvent e)
 40:     {
 41:         contentPane.setBackground(Color.PINK);
 42:         response.setVisible(true);
 43:     }
 44: }