lgm1418973707

1、运用事件处理相关知识,完成两个窗口之间的切换,例如:登陆窗口------》注册窗口

 

package ccc;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class lgm implements ActionListener{
JFrame f1,f2;
JButton b1,b2;
JPanel p;
JLabel l1,l2;
JTextField t1,t2;
public lgm() {
f1=new JFrame("登录界面");
b1=new JButton("登录");
b1.addActionListener(new b1buton());
b2=new JButton("注册");
b2.addActionListener(new b2buton());
p=new JPanel();
p.add(b1);
p.add(b2);
f1.add(p);
f1.setLocation(100, 100);
f1.setSize(800, 700);
f1.setVisible(true);
}
public static void main(String[]arge){
new lgm();
}
class b1buton implements ActionListener{
public void actionPerformed(ActionEvent e) {
f1.setVisible(true);
f2=new JFrame("注册界面");
l1=new JLabel("账号:");
t1=new JTextField(30);
l2=new JLabel("密码");
t2=new JTextField(30);
p=new JPanel();
p.setBackground(Color.yellow);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
f1.add(p);
f2.add(p);
f2.setLocation(900, 100);
f2.setSize(800, 700);
f2.setVisible(true);
}
}
class b2buton implements ActionListener{
public void actionPerformed(ActionEvent e) {
f1.setVisible(true);
f2=new JFrame("注册界面");
l1=new JLabel("账号:");
t1=new JTextField(30);
l2=new JLabel("密码");
t2=new JTextField(30);
p=new JPanel();
p.setBackground(Color.blue);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b2);
f2.add(p);
f2.setLocation(900, 100);
f2.setSize(800, 700);
f2.setVisible(true);
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub

}
}

 

 

 

 

 

 

分类:

技术点:

相关文章:

  • 2021-05-06
  • 2021-10-16
  • 2021-12-04
  • 2021-11-14
  • 2021-06-04
  • 2021-10-16
  • 2021-11-23
  • 2021-10-16
猜你喜欢
  • 2021-12-05
  • 2021-04-18
  • 2021-10-12
  • 2021-11-19
  • 2021-06-11
相关资源
相似解决方案