JavaGUI登陆界面,使用IO

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Login {
private JLabel labelId , labelPwd;
private JTextField jTextFieldId , jTextFieldPwd;
private JButton buttonLogin;
public JFrame loginUi() {
int width=518;
int height=400;
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
JFrame jFrame = new JFrame();
//jFrame.setUndecorated(true);//无边框
jFrame.setBounds((d.width - width) / 2, (d.height - height) / 2, width, height);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setLayout(null);//空布局
labelId = new JLabel(“账号 :”);
labelPwd = new JLabel(“密码 :”);
labelId.setBounds(140, 100, 50, 32);
labelPwd.setBounds(140, 152, 50, 32);
jFrame.add(labelId);
jFrame.add(labelPwd);
jTextFieldId = new JTextField();//创建输入框
jTextFieldPwd = new JTextField();//创建输入框
jTextFieldId.setBounds(180, 100, 200, 32);
jTextFieldPwd.setBounds(180, 152, 200, 32);
jFrame.add(jTextFieldId);
jFrame.add(jTextFieldPwd);
buttonLogin = new JButton(“登陆”);
buttonLogin.setBounds(180, 202, 80, 32);
JButton buttonZc = new JButton(“注册”);
buttonZc.setBounds(280,202,80,32);
jFrame.add(buttonZc);
jFrame.add(buttonLogin);
buttonZc .addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Register().registerUi().setVisible(true);
}
});
buttonLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//获取文本框内容
String id = jTextFieldId.getText();//获取账号
String passWord = jTextFieldPwd.getText();//获取密码
boolean nullText =false;//验证登陆变量
if (id.equals("")||passWord.equals("")) {
JOptionPane.showMessageDialog(null, “密码和账号不能为空”);
}
else {
/*
* 读取文件
*/
}
}
});
return jFrame;
}
public static void main(String[] args) {
new Login().loginUi().setVisible(true);
}
}

你可能感兴趣的:(java)