基于java+swing的通讯聊天程序(java+swing)
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
} else {
JOptionPane.showMessageDialog(null, "用户名已经存在!");
}
} else {
JOptionPane.showMessageDialog(null, "密码确认不符!");
}
} else {
JOptionPane.showMessageDialog(null, "未输入确认密码!");
}
} else {
JOptionPane.showMessageDialog(null, "未输入密码!");
}
} else {
JOptionPane.showMessageDialog(null, "未输入用户名!");
}
}
}
/**
* Create the frame.
*/
public SignFrame() {
setTitle("\u7528\u6237\u6CE8\u518C");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 364);
LoginFrame frame = new LoginFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public LoginFrame() {
setTitle("\u7F51\u4E0A\u94F6\u884C");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 506, 385);
contentPane = new JPanel();
setLocationRelativeTo(null);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton LoginButton = new JButton("\u767B\u5F55");
LoginButton.setFont(new Font("新宋体", Font.BOLD, 20));
JOptionPane.showMessageDialog(null, "找不到该用户,请先注册!");
u_name_Field.setText("");
u_password_field.setText("");
}
}
}
//注册事件监听器
class signAction implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
SignFrame frame = new SignFrame();
frame.setVisible(true);
setVisible(false);
}
}
/**
* Launch the application.
JOptionPane.showMessageDialog(null, "未输入密码!");
}
} else {
JOptionPane.showMessageDialog(null, "未输入用户名!");
}
}
}
/**
* Create the frame.
*/
public SignFrame() {
setTitle("\u7528\u6237\u6CE8\u518C");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 364);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
setLocationRelativeTo(null);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("\u7528\u6237\u540D\uFF1A");
lblNewLabel.setFont(new Font("新宋体", Font.BOLD, 18));
lblNewLabel.setBounds(74, 78, 102, 34);
contentPane.add(lblNewLabel);
u_name.setBounds(187, 85, 123, 24);
contentPane.add(u_name);
u_name.setColumns(10);
u_password = new JPasswordField();
u_password.setBounds(187, 153, 123, 24);
contentPane.add(u_password);
u_password_1 = new JPasswordField();
u_password_1.setBounds(187, 215, 123, 24);
contentPane.add(u_password_1);
JButton OKButton = new JButton("\u786E\u5B9A");
OKButton.setFont(new Font("新宋体", Font.BOLD, 20));
OKButton.setBounds(171, 277, 113, 27);
contentPane.add(OKButton);
OKButton.addActionListener(new OKButtonAction());
}
private JTextField u_name_Field;
private JPasswordField u_password_field;
private user user;
//登录事件监听器
class loginAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
user = ExecuteSQL.check(u_name_Field.getText(), u_password_field.getText());
if (user.getName() != null) {
if (user.getPassword().equals(u_password_field.getText())) {
try {
atmFrame frame = new atmFrame(user.getName());
frame.setTitle(user.getName());
frame.setVisible(true);
setVisible(false);
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(null, "密码不正确!请重新输入");
u_name_Field.setText("");
u_password_field.setText("");
}
} else {
setVisible(false);
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(null, "密码不正确!请重新输入");
u_name_Field.setText("");
u_password_field.setText("");
}
} else {
JOptionPane.showMessageDialog(null, "找不到该用户,请先注册!");
u_name_Field.setText("");
u_password_field.setText("");
}
}
}
setContentPane(contentPane);
setLocationRelativeTo(null);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("\u7528\u6237\u540D\uFF1A");
lblNewLabel.setFont(new Font("新宋体", Font.BOLD, 18));
lblNewLabel.setBounds(74, 78, 102, 34);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("\u5BC6\u7801\uFF1A");
lblNewLabel_1.setFont(new Font("新宋体", Font.BOLD, 18));
lblNewLabel_1.setBounds(88, 149, 88, 28);
contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A");
lblNewLabel_2.setFont(new Font("新宋体", Font.BOLD, 18));
lblNewLabel_2.setBounds(69, 211, 101, 28);
contentPane.add(lblNewLabel_2);
u_name = new JTextField();
u_name.setBounds(187, 85, 123, 24);
contentPane.add(u_name);
u_name.setColumns(10);
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LoginFrame frame = new LoginFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public LoginFrame() {
setTitle("\u7F51\u4E0A\u94F6\u884C");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 506, 385);
contentPane = new JPanel();
/**
* Create the frame.
*/
public LoginFrame() {
setTitle("\u7F51\u4E0A\u94F6\u884C");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 506, 385);
contentPane = new JPanel();
setLocationRelativeTo(null);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton LoginButton = new JButton("\u767B\u5F55");
LoginButton.setFont(new Font("新宋体", Font.BOLD, 20));
LoginButton.setBounds(92, 214, 120, 37);
contentPane.add(LoginButton);
LoginButton.addActionListener(new loginAction());