Java Reference
In-Depth Information
Display 18.9
Labels with Changing Visibility (part 2 of 3)
20
VisibilityDemo demoGui = new VisibilityDemo();
21
demoGui.setVisible( true );
22
}
23
public VisibilityDemo()
24
{
25
setSize(WIDTH, HEIGHT);
26
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
27
setTitle("Visibility Demonstration");
28
setLayout( new BorderLayout());
29
JPanel picturePanel = new JPanel();
30
picturePanel.setBackground(Color.WHITE);
31
picturePanel.setLayout( new FlowLayout());
32
ImageIcon dukeStandingIcon =
33
new ImageIcon("duke_standing.gif");
34
standingLabel = new JLabel(dukeStandingIcon);
35
standingLabel.setVisible( true );
36
picturePanel.add(standingLabel);
37
ImageIcon dukeWavingIcon = new ImageIcon("duke_waving.gif");
38
wavingLabel = new JLabel(dukeWavingIcon);
39
wavingLabel.setVisible( false );
40
picturePanel.add(wavingLabel);
41
add(picturePanel, BorderLayout.CENTER);
42
JPanel buttonPanel = new JPanel();
43
buttonPanel.setBackground(Color.LIGHT_GRAY);
44
buttonPanel.setLayout( new FlowLayout());
45
JButton waveButton = new JButton("Wave");
46
waveButton.addActionListener( this );
47
buttonPanel.add(waveButton);
48
JButton stopButton = new JButton("Stop");
49
stopButton.addActionListener( this );
50
buttonPanel.add(stopButton);
51
add(buttonPanel, BorderLayout.SOUTH);
52
}
53
public void actionPerformed(ActionEvent e)
54
{
55
String actionCommand = e.getActionCommand();
(continued)
Search WWH ::




Custom Search