关于java中CardLayout的问题
importjava.awt.*;importjava.awt.event.*;publicclassLogingimplementsActionListener{Fra...
import java.awt.*;
import java.awt.event.*;
public class Loging implements ActionListener{
Frame log;
Button b1,b2,bb1;
TextField t1,t2;
Label l1,l2,ll1;
Panel p1,p2,p3,pf1,pf2;
CardLayout card=new CardLayout();
public void show()
{
log=new Frame("登录");
log.setLayout(new CardLayout());
pf1=new Panel();
log.add(pf1,"f1");
pf1.setLayout(new GridLayout(3,1));
log.setSize(400,300);
l1=new Label("用户名:");
l2=new Label("密码: ");
b1=new Button("确定");
b2=new Button("取消");
t1=new TextField(20);
t2=new TextField(20);
p1=new Panel();
p2=new Panel();
p3=new Panel();
pf1.add(p1);
pf1.add(p2);
pf1.add(p3);
p1.add(l1);
p1.add(t1);
p2.add(l2);
p2.add(t2);
p3.add(b1);
p3.add(b2);
pf2=new Panel();
ll1=new Label("转不到???");
bb1=new Button("确定");
pf2.add(ll1);
pf2.add(bb1);
log.add(pf2,"f2");
log.setVisible(true);
log.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
card.show(log,"f2");
}
}
public static void main(String args[]){
(new Loging()).show();
}
}
想要设计成按了确定以后可以跳到第二张卡片,提示用户,输入是否正确。怎么改才对? 展开
import java.awt.event.*;
public class Loging implements ActionListener{
Frame log;
Button b1,b2,bb1;
TextField t1,t2;
Label l1,l2,ll1;
Panel p1,p2,p3,pf1,pf2;
CardLayout card=new CardLayout();
public void show()
{
log=new Frame("登录");
log.setLayout(new CardLayout());
pf1=new Panel();
log.add(pf1,"f1");
pf1.setLayout(new GridLayout(3,1));
log.setSize(400,300);
l1=new Label("用户名:");
l2=new Label("密码: ");
b1=new Button("确定");
b2=new Button("取消");
t1=new TextField(20);
t2=new TextField(20);
p1=new Panel();
p2=new Panel();
p3=new Panel();
pf1.add(p1);
pf1.add(p2);
pf1.add(p3);
p1.add(l1);
p1.add(t1);
p2.add(l2);
p2.add(t2);
p3.add(b1);
p3.add(b2);
pf2=new Panel();
ll1=new Label("转不到???");
bb1=new Button("确定");
pf2.add(ll1);
pf2.add(bb1);
log.add(pf2,"f2");
log.setVisible(true);
log.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
card.show(log,"f2");
}
}
public static void main(String args[]){
(new Loging()).show();
}
}
想要设计成按了确定以后可以跳到第二张卡片,提示用户,输入是否正确。怎么改才对? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询