java cardlayout问题
怎么运用java的cardlayout格式制作出,安装软件是的界面,就是可以狂点下一步的那个,最好每个界面可以有一个按键或文本框什么的!谢谢了!!急急急。。。。如果答案满...
怎么运用java的cardlayout格式制作出,安装软件是的界面,就是可以狂点下一步的那个,最好每个界面可以有一个按键或文本框什么的!谢谢了!!急急急。。。。如果答案满意,分数追加给。。。。
展开
1个回答
展开全部
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test {
private JFrame frame;
private JLabel l1;
private JLabel l2;
private JLabel l3;
private JButton b1;
private JButton b2;
private CardLayout c;
private Panel p1;
private Panel p2;
public Test(){
frame=new JFrame("Test");
c=new CardLayout();
l1=new JLabel("Label1");
l2=new JLabel("Label2");
l3=new JLabel("Label3");
b1=new JButton("<-");
b2=new JButton("->");
p1=new Panel();
p2=new Panel();
frame.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
p1.setLayout(c);
l1.setBackground(Color.red);
l2.setBackground(Color.green);
l3.setBackground(Color.blue);
p1.add("a",l1);//用“1”,“one”皆可
p1.add("b",l2);
p1.add("c",l3);
frame.add(p1);
p2.setLayout(new FlowLayout(FlowLayout.CENTER,0,50));
p2.add(b1);
p2.add(b2);
frame.add(p2);
frame.setVisible(true);
frame.setSize(250,150);
frame.setLocation(200,200);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1){
c.previous(p1);//上一个
}
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b2)c.next(p1);
}
});
}
public static void main(String[] args) {
new Test();
}
}
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test {
private JFrame frame;
private JLabel l1;
private JLabel l2;
private JLabel l3;
private JButton b1;
private JButton b2;
private CardLayout c;
private Panel p1;
private Panel p2;
public Test(){
frame=new JFrame("Test");
c=new CardLayout();
l1=new JLabel("Label1");
l2=new JLabel("Label2");
l3=new JLabel("Label3");
b1=new JButton("<-");
b2=new JButton("->");
p1=new Panel();
p2=new Panel();
frame.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
p1.setLayout(c);
l1.setBackground(Color.red);
l2.setBackground(Color.green);
l3.setBackground(Color.blue);
p1.add("a",l1);//用“1”,“one”皆可
p1.add("b",l2);
p1.add("c",l3);
frame.add(p1);
p2.setLayout(new FlowLayout(FlowLayout.CENTER,0,50));
p2.add(b1);
p2.add(b2);
frame.add(p2);
frame.setVisible(true);
frame.setSize(250,150);
frame.setLocation(200,200);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1){
c.previous(p1);//上一个
}
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b2)c.next(p1);
}
});
}
public static void main(String[] args) {
new Test();
}
}
更多追问追答
追问
你能不能在每一个卡片里加上按键,文本框,文本区,一类的东西,每个卡片的东西不一样,谢谢了!
追答
不是有个label显示的不一样了么..
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询