⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.java

📁 简单的实现了一个人事资源管理系统
💻 JAVA
字号:
package mypackage;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;

public class Login extends JFrame {

	protected static final Component JDialog =null;
	private JPasswordField jTextField1;
	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Login frame ;
		//	if(frame.isShowing())
				frame= new Login();
			frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the frame
	 */
	public Login() {
		super();
		 setVisible(true);

		setTitle("用户登录");
		setBounds(100, 100, 369, 205);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		getContentPane().add(panel, BorderLayout.CENTER);

		final JLabel label_1 = new JLabel();
		label_1.setFont(new Font("", Font.BOLD, 14));
		label_1.setText("口令:");
		label_1.setBounds(95, 58, 60, 15);
		panel.add(label_1);

		final JButton jButton1 = new JButton();
		jButton1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			try {
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				String url="jdbc:odbc:Password";
				Connection conn=DriverManager.getConnection(url,"","");
				Statement stmt=conn.createStatement();
				ResultSet rs=stmt.executeQuery("select * from User where Pass='"+String.valueOf(jTextField1.getPassword())+"'");
				System.out.println("数据库查询结束"+String.valueOf(jTextField1.getPassword()));
				if(!rs.next())
				{
					JOptionPane.showMessageDialog(JDialog,"您输入的口令不正确!请重写!","提示",JOptionPane.ERROR_MESSAGE);
				}
				else
				{
					rs.close();
					stmt.close();
					conn.close();
					dispose();
					(new MainFrame()).setVisible(true);
				}
			} catch (ClassNotFoundException e) {
				// TODO 自动生成 catch 块
				System.out.println("没有找到类驱动!");
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				System.out.println("数据库抛出异常!");
				e.printStackTrace();
			}
			}
		});
		jButton1.setText("登录");
		jButton1.setBounds(95, 111, 69, 23);
		panel.add(jButton1);

		final JButton jButton2 = new JButton();
		jButton2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		jButton2.setText("取消");
		jButton2.setBounds(215, 111, 69, 23);
		panel.add(jButton2);

		jTextField1 = new JPasswordField();
		jTextField1.setBounds(161, 54, 135, 23);
		panel.add(jTextField1);
		//
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -