1、运用事件处理相关知识,完成两个窗口之间的切换,例如:登陆窗口------》注册窗口
2、对本次作业进行总结,在编程过程中遇到哪些问题,如何解决,有哪些收获
import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class jck { JFrame f; JPanel p,p1; JButton b1,b2; JLabel l,l1,l2; JTextField t1; JPasswordField t2; public jck() { f=new JFrame("QQ"); p=new JPanel(); p1=new JPanel(); p.setLayout(null); p1.setLayout(null); b1=new JButton("登录"); b2=new JButton("注册"); l=new JLabel("账号:"); l1=new JLabel("密码:"); l2=new JLabel("登陆成功!"); t1=new JTextField(5); t2=new JPasswordField(5); t1.setBounds(180, 82, 200, 28); t2.setBounds(180, 140, 200, 28); b1.setBounds(120, 210, 80, 28); b2.setBounds(300, 210, 80, 28); l.setBounds(140, 82, 80, 30); l1.setBounds(140,140, 80, 30); l2.setBounds(200,120,80,30); f.add(p); p.add(l); p.add(t1); p.add(l1); p.add(t2); p.add(b2); p.add(b1); f.setVisible(true); f.setLocation(700, 400); f.setSize(500, 350); b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { f.setVisible(false); JFrame f1=new JFrame("QQ"); f1.setVisible(true); f1.add(p1); p1.add(l2); f1.setLocation(700, 400); f1.setSize(500,350); } }); } public static void main(String[] args) { new jck(); } }
心得体会:打窗口这类代码比较有意思,也是比较实用的,同时打的代码量也增加了,难免会有些浮躁,再就是自几会打错一些错误的代码,但想到以后可以打出跟高级的代码,也还是可以接受现在的这种浮躁。