cardLayout 我想实现一个 "下一页" 这样的按钮;那么我用cardLayout()布局,把许多个面板叠在一起可以么???请给我举个简单例子. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html import java.awt.*;import java.awt.event.*;import javax.swing.*;public class CardLayoutDemo implements ActionListener{ JPanel p1,p2,p3,p4; int i = 1; JFrame f; public CardLayoutDemo() { f = new JFrame(); Container contentPane = f.getContentPane(); contentPane.setLayout(new GridLayout(2,1)); p1 = new JPanel(); Button b = new Button("Change Card"); b.addActionListener(this); p1.add(b); contentPane.add(p1); p2 = new JPanel(); p2.setLayout(new FlowLayout()); p2.add(new JButton("first")); p2.add(new JButton("second")); p2.add(new JButton("third")); p3 = new JPanel(); p3.setLayout(new GridLayout(3,1)); p3.add(new JButton("fourth")); p3.add(new JButton("fifth")); p3.add(new JButton("This is the last button")); p4 = new JPanel(); p4.setLayout(new CardLayout()); p4.add("one",p2); p4.add("two",p3); ((CardLayout)p4.getLayout()).show(p4,"one"); contentPane.add(p4); f.setTitle("CardLayout"); f.pack(); f.setVisible(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public void actionPerformed(ActionEvent event) { switch(i) { case 1: ((CardLayout)p4.getLayout()).show(p4,"two"); break; case 2: ((CardLayout)p4.getLayout()).show(p4,"one"); break; } i++; if (i==3) i=1; f.validate(); } public static void main(String args[]) { new CardLayoutDemo(); }} 数值类型提升问题 Java调用php 在B包中是否可以实现A包中的接口问题 请高手们都出来看看 新建SWT/Jface 群 18687738 怎么样将一个目录打包成jar包? 关于文件的解析?? HashMap是什么东东?Map.Entry又是什么意思 请指教!一下啊,就好 请网友帮助查看这段出错代码,功能:从Sql server2000中读取数据 急急急!! 在用myeclipse+tomcat调试带有jsf页面的时候出现以下错误!!!! 继承类的构造器问题
import java.awt.event.*;
import javax.swing.*;public class CardLayoutDemo implements ActionListener{
JPanel p1,p2,p3,p4;
int i = 1;
JFrame f;
public CardLayoutDemo() {
f = new JFrame();
Container contentPane = f.getContentPane();
contentPane.setLayout(new GridLayout(2,1));
p1 = new JPanel();
Button b = new Button("Change Card");
b.addActionListener(this);
p1.add(b);
contentPane.add(p1);
p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(new JButton("first"));
p2.add(new JButton("second"));
p2.add(new JButton("third"));
p3 = new JPanel();
p3.setLayout(new GridLayout(3,1));
p3.add(new JButton("fourth"));
p3.add(new JButton("fifth"));
p3.add(new JButton("This is the last button"));
p4 = new JPanel();
p4.setLayout(new CardLayout());
p4.add("one",p2);
p4.add("two",p3);
((CardLayout)p4.getLayout()).show(p4,"one");
contentPane.add(p4);
f.setTitle("CardLayout");
f.pack();
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent event)
{
switch(i)
{
case 1:
((CardLayout)p4.getLayout()).show(p4,"two");
break;
case 2:
((CardLayout)p4.getLayout()).show(p4,"one");
break;
}
i++;
if (i==3)
i=1;
f.validate();
}
public static void main(String args[]) {
new CardLayoutDemo();
}
}