-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardLayoutDemo.java
49 lines (49 loc) · 1.64 KB
/
CardLayoutDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code="CardLayoutDemo" width=300 height=100> </applet> */
public class CardLayoutDemo extends Applet implements ActionListener {
Checkbox Win98, winNT, solaris, mac;
Panel osCards;
CardLayout cardLO;
Button Win, Other;
public void init()
{
Win = new Button("Windows");
Other = new Button("Other");
add(Win);
add(Other);
cardLO = new CardLayout();
osCards = new Panel();
osCards.setLayout(cardLO); // set panel layout to card layout
Win98 = new Checkbox("Windows 98/XP", null, true);
winNT = new Checkbox("Windows NT/2000");
solaris = new Checkbox("Solaris");
mac = new Checkbox("MacOS");
winPan = new Panel();
winPan.add(Win98); winPan.add(winNT);
// Add other OS check boxes to a panel Panel
otherPan = new Panel();
otherPan.add(solaris);
otherPan.add(mac);
// add panels to card deck panel
osCards.add(winPan, "Windows");
osCards.add(otherPan, "Other");
// add cards to main applet panel
add(osCards);
// register to receive action events
Win.addActionListener(this);
Other.addActionListener(this);
// register mouse events addMouseListener(this);
}
// Cycle through panels. public void mousePressed(MouseEvent me) { cardLO.next(osCards); }
// Provide empty implementations for the other MouseListener methods. public void mouseClicked(MouseEvent me) { } public void mouseEntered(MouseEvent me) { } public void mouseExited(MouseEvent me) { } public void mouseReleased(MouseEvent me) { }
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == Win)
{
cardLO.show(osCards, "Windows");
}
else
{ cardLO.show(osCards, "Other"); }
}
}