这是老师布置的作业,实现界面和监听。本人采用了GridBagLayout布局。先放上效果图
当鼠标放到file和about时,分别显示
点击exit执行退出操作
点击update和information分别会弹出一个提示框
账号和密码有限制位数和形式,点击checkinfo会进行检查,并在左下的status栏显示是否合法,register表示注册,用户登录名和密码存在文件中
注册成功时的txt文件
点击color按钮,会在两种颜色之间切换,点击center,整体移动到电脑屏幕中央位置。
窗口类
import javax.swing.*;
import java.awt.*;
public class Chuangkou extends JFrame{
public JMenu file;
public JMenu about;
public JPanel blank2;
public JButton checkinfo;
public JButton color;
public JButton center;
public JButton register;
public JTextField email;
public JPasswordField password;
public JTextField status;
public JTextArea blank3;
public JMenuBar br;
public JMenuItem exit;
public JMenuItem update;
public JMenuItem information;
public Chuangkou() {
init();
this.setTitle("Hello World");
this.pack();
this.setSize(377,230);
this.setVisible(true);
// this.setBackground(Color.BLUE);//设置背景色为蓝色
// this.getContentPane().setVisible(true);
this.getContentPane().setBackground(Color.WHITE);
// this.setLocationRelativeTo(null);//位于中间
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void init() {
file=new JMenu("File");
about=new JMenu("About");
blank2=new JPanel();
email=new JTextField(15);
password=new JPasswordField(15);
register=new JButton("Register");
checkinfo=new JButton("Check Info");
color=new JButton(" Color ");
center=new JButton(" Center ");
status=new JTextField("stutas");
blank3=new JTextArea();
br=new JMenuBar();
exit=new JMenuItem("Exit");
update=new JMenuItem(