package test;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import java.awt.Component;
import javax.swing.Box;
import java.awt.Panel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.Frame;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.JTextPane;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.Color;
import javax.swing.JPasswordField;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
public class ATMLogin extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JPasswordField passwordField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ATMLogin frame = new ATMLogin();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @param name2
*/
public ATMLogin() {
/*setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));*/
setBackground(new Color(255, 255, 255));
setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 907, 513);
contentPane = new JPanel();
contentPane.setBackground(new Color(255, 255, 255));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("");
btnNewButton.setBounds(10, 57, 107, 45);
contentPane.add(btnNewButton);
JButton btnNewButton_1 = new JButton("");
btnNewButton_1.setBounds(10, 168, 107, 45);
contentPane.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("\u6CE8\u518C");
btnNewButton_2.setToolTipText("");
btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 20));
btnNewButton_2.setBounds(10, 280, 107, 45);
contentPane.add(btnNewButton_2);
JButton btnNewButton_3 = new JButton("\u53D6\u6D88");
btnNewButton_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField.setText(null);
passwordField.setText(null);
}
});
btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 20));
btnNewButton_3.setBounds(10, 392, 107, 45);
contentPane.add(btnNewButton_3);
JButton btnNewButton_4 = new JButton("");
btnNewButton_4.setBounds(775, 57, 107, 45);
contentPane.add(btnNewButton_4);
JButton btnNewButton_1_1 = new JButton("");
btnNewButton_1_1.setBounds(775, 168, 107, 45);
contentPane.add(btnNewButton_1_1);
JButton btnNewButton_2_1 = new JButton("");
btnNewButton_2_1.setBounds(775, 280, 107, 45);
contentPane.add(btnNewButton_2_1);
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(255, 255, 255));
panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u767B\u9646\u7A97\u53E3", TitledBorder.CENTER, TitledBorder.TOP,new Font("楷体", Font.PLAIN, 20), new Color(255, 0, 0)));
panel_1.setBounds(127, 10, 638, 440);
contentPane.add(panel_1);
panel_1.setLayout(null);
Panel panel = new Panel();
panel.setBackground(new Color(255, 255, 255));
panel.setBounds(10, 24, 618, 406);
panel_1.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("\u8D26\u53F7\uFF1A");
lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
lblNewLabel.setBounds(135, 88, 78, 44);
panel.add(lblNewLabel);
JLabel lblNewLabel_2 = new JLabel("\u5BC6\u7801\uFF1A");
lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 20));
lblNewLabel_2.setBounds(135, 190, 78, 44);
panel.add(lblNewLabel_2);
textField = new JTextField();
textField.setFont(new Font("宋体", Font.PLAIN, 20));
textField.setBounds(242, 91, 253, 44);
panel.add(textField);
textField.setColumns(10);
passwordField = new JPasswordField();
passwordField.setFont(new Font("宋体", Font.PLAIN, 20));
passwordField.setEchoChar('*');
passwordField.setBounds(242, 193, 253, 44);
panel.add(passwordField);
JButton btnNewButton_3_1 = new JButton("\u786E\u8BA4");
btnNewButton_3_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String sql2 = "select * from atm where binary name ="+"'"+textField.getText()+"'"+"and binary password="+"'"+passwordField.getText()+"'";
DBHelper dbHelper = new DBHelper();
ResultSet rsResultSet = dbHelper.DB(sql2);
if(rsResultSet.next()==true){
JOptionPane.showMessageDialog(passwordField, "登录成功!", "提示:",JOptionPane.WARNING_MESSAGE);
dbHelper.downConn();
else if(textField.getText().length()==0 && passwordField.getText().length()!=0) {
JOptionPane.showMessageDialog(panel_1, "登录失败!\n用户名不可为空!", "错误提示:",JOptionPane.WARNING_MESSAGE);
}
else if(textField.getText().length()!=0 && passwordField.getText().length()==0) {
JOptionPane.showMessageDialog(panel_1, "登录失败!\n密码不可为空!", "错误提示:",JOptionPane.WARNING_MESSAGE);
}
else if(textField.getText().length()==0 && passwordField.getText().length()==0){
JOptionPane.showMessageDialog(panel_1, "登录失败!\n用户名和密码不可为空", "错误提示:",JOptionPane.WARNING_MESSAGE);
}
else {
textField.setText(null);
passwordField.setText(null);
JOptionPane.showMessageDialog(panel_1, "登录失败!\n用户名不存在或者密码不正确!", "错误提示:",JOptionPane.WARNING_MESSAGE);
}
}
catch (Exception e1) {
}
}
});
btnNewButton_3_1.setFont(new Font("宋体", Font.PLAIN, 20));
btnNewButton_3_1.setBounds(775, 392, 107, 45);
contentPane.add(btnNewButton_3_1);
}
}
Java一个简单的登录界面
最新推荐文章于 2024-09-12 01:15:37 发布
这是一个简单的Java Swing应用,用于创建一个ATM登录界面。用户界面包含登录、注册、取消和确认按钮,以及输入框用于接收用户名和密码。登录功能通过查询数据库验证用户输入的用户名和密码是否匹配。如果信息无效,会显示相应的错误提示。
摘要由CSDN通过智能技术生成