📄 dialog.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class Dialog extends Frame implements ActionListener
{
Label label1 = new Label("用户名");
Label label2=new Label("密码");
TextField textField1 = new TextField();
TextField textField2=new TextField();
Button button1 = new Button("确定");
Button button2 = new Button("取消");
int n;
Connection conn;
Statement stmt;
ResultSet rs;
String strurl;
Dialog() throws Exception
{
super("登陆窗口");
setSize(400,300);
setBackground(new Color(0,100,255));
this.setLocation(200,200);
setLayout(null);
label1.setBounds(91, 74, 66, 21);
label2.setBounds(91, 120, 63, 22);
textField1.setBounds(165, 74, 114, 21);
textField2.setBounds(165, 118, 114, 24);
textField2.setEchoChar('*');
button2.addActionListener(this);
button1.setBounds(87, 197, 79, 27);
button2.setBounds(200, 198, 85, 26);
button1.addActionListener(this);
add(label1);
add(label2);
add(textField2);
add(textField1);
add(button1);
add(button2);
strurl ="jdbc:odbc:book";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection conn=DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=bookshop/db/db.mdb;");
conn = DriverManager.getConnection(strurl);
stmt = conn.createStatement();
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
String sql;
String user,pass;
if (str.equals("确定"))
{
user=textField1.getText().trim();
pass=textField2.getText().trim();
try
{
rs = stmt.executeQuery("select * from admininfo where username ='" + user + "' AND password='" + pass + "'");
if (rs.next())
{
Manage_System frame=new Manage_System();
setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null, "用户不存在!");
textField1.setText("");
textField2.setText("");
}
}
catch (Exception eg) {
eg.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -