Java Reference
In-Depth Information
private void createAppletGUI() {
Container content = getContentPane();
content.setLayout(card);
// Set card as the
layout mgr
JButton button;
// Stores a button
for(int i = 1; i <= 6; ++i) {
// Add a button
content.add(button = new JButton(" Press " + i), "Card" + i);
button.addActionListener(this);
// Add listener for
button
}
card.show(content, "Card5");
// Show the 5th
card to start
}
// Handle button events
public void actionPerformed(ActionEvent e) {
card.next(getContentPane());
// Switch to the
next card
}
private CardLayout card = new CardLayout(50,50);// The layout
manager
}
Directory "TryCardLayout"
You need an HTML file to execute the applet containing the following:
<html>
<head> </head>
<body bgcolor="000000">
<center>
<applet
code = "TryCardLayout.class"
width = "500"
height = "300"
>
</applet>
</center>
</body>
</html>
If you run the program using appletviewer , the applet should be as shown in Figure 17-20 . Click the
button showing to display the next button.
FIGURE 17-20
 
 
Search WWH ::




Custom Search