58,454
社区成员
发帖
与我相关
我的任务
分享
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.awt.CardLayout;
public class Sb_5_7 extends Applet implements ActionListener {
// 卡布局
JLabel l1 = new JLabel("one");
JLabel l2 = new JLabel("two");
JButton b1 = new JButton("向前");
JButton b2 = new JButton("向后");
CardLayout card = new CardLayout(5,5);
BorderLayout bord = new BorderLayout();
JFrame f;
JPanel p1;
JPanel p2;
public void init() {
f = new JFrame();
Container con = f.getContentPane();
con.setLayout(bord);
setSize(400, 150);
setVisible(true);
p1 = new JPanel();
p1.setLayout(card);
p1.add(l1,"a");
p1.add(l2,"b");
p2 = new JPanel();
b1.addActionListener(this);
b2.addActionListener(this);
p2.add(b1);
p2.add(b2);
con.add(p1, "Center");
con.add(p2, "South");
f.pack();
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("向前"))
card.last(p1);
else
card.next(p1);
}
}