📄 reggui.java
字号:
package gui;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import model.Conn;
import model.Database;
import vo.UserinfoVO;
public class Reggui extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private Connection conn = null;
private JPanel jp1 = null;
private JPanel jp2 = null;
private JTextField tf_name = null;
private JPasswordField pf_pwd = null;
private JLabel l_name = null;
private JLabel l_pwd = null;
private JButton ok = null;
private JButton cancel = null;
private JButton clear = null;
public Reggui(){
try {
conn = new Conn().getConnection();
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, "数据库连接错误!");
} catch (SQLException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, e.getMessage());
}
jp1 = new JPanel(new GridLayout(2, 2, 5, 5));
jp2 = new JPanel(new GridLayout(1, 3, 10, 10));
tf_name = new JTextField(15);
pf_pwd = new JPasswordField(15);
l_name = new JLabel("用 户 名:", JLabel.CENTER);
l_pwd = new JLabel("密 码:", JLabel.CENTER);
ok = new JButton("确定");
cancel = new JButton("注册");
cancel = new JButton("取消");
clear = new JButton("清空");
jp1.add(l_name);
jp1.add(tf_name);
jp1.add(l_pwd);
jp1.add(pf_pwd);
jp2.add(ok);
jp2.add(cancel);
jp2.add(clear);
this.add(jp1);
this.add(jp2, BorderLayout.SOUTH);
this.pack();
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ok.addActionListener(this);
cancel.addActionListener(this);
clear.addActionListener(this);
}
/*
* public static void main(String arg[]) throws ClassNotFoundException,
* SQLException{ Logingui lg = new Logingui(); }
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(ok)) {
String username = tf_name.getText().trim();
String password = pf_pwd.getText().trim();
if(username != null && password != null && !"".equals(username) && !"".equals(password)){
try {
UserinfoVO uvo = new UserinfoVO();
uvo.setUsername(username);
uvo.setPassword(password);
System.out.println(uvo.getUsername());
new Database().regist(uvo);
JOptionPane.showMessageDialog(null, "注册成功!");
this.setVisible(false);
Logingui lg = new Logingui();
lg.setVisible(true);
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
tf_name.setText("");
pf_pwd.setText("");
return;
} catch (ClassNotFoundException e1) {
JOptionPane.showMessageDialog(null, "数据库连接错误!");
}
}
else{
JOptionPane.showMessageDialog(null, "用户名或密码错误,请重新输入!");
}
}
if (e.getSource().equals(cancel)) {
JOptionPane.showMessageDialog(null, "感谢使用本系统");
return;
}
if (e.getSource().equals(clear)) {
tf_name.setText("");
tf_name.setText("");
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -