forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
36 lines (33 loc) · 939 Bytes
/
Copy pathCard.java
File metadata and controls
36 lines (33 loc) · 939 Bytes
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
//file: Card.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Card extends JPanel {
CardLayout cards = new CardLayout();
public Card() {
setLayout(cards);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
cards.next(Card.this);
}
};
JButton button;
button = new JButton("one");
button.addActionListener(listener);
add(button, "one");
button = new JButton("two");
button.addActionListener(listener);
add(button, "two");
button = new JButton("three");
button.addActionListener(listener);
add(button, "three");
}
public static void main(String[] args) {
JFrame frame = new JFrame("Card");
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize(200, 200);
frame.setLocation(200, 200);
frame.setContentPane(new Card());
frame.setVisible(true);
}
}