📄 dialog.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class Dialog extends Frame implements ActionListener,ItemListener
{
Label label1 = new Label("用户名");
Label label2=new Label("密码");
Label label3=new Label("登陆类型");
TextField textField1 = new TextField();
TextField textField2=new TextField();
Choice choice1=new Choice();
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(110,200,150));
this.setLocation(200,200);
choice1.add("普通用户");
choice1.add("超级用户");
setLayout(null);
label1.setBounds(91, 74, 66, 21);
label2.setBounds(91, 120, 63, 22);
label3.setBounds(91,160,63,22);
textField1.setBounds(165, 74, 114, 21);
textField2.setBounds(165, 118, 114, 24);
textField2.setEchoChar('*');
choice1.setBounds(165, 160, 114, 24);
choice1.addItemListener(this);
button2.addActionListener(this);
button1.setBounds(87, 197, 79, 27);
button2.setBounds(200, 198, 85, 26);
button1.addActionListener(this);
add(label1);
add(label2);
add(label3);
add(textField2);
add(textField1);
add(choice1);
add(button1);
add(button2);
strurl ="jdbc:odbc:tianxia";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(strurl,"sa","");
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();
if (n==0)
{
try
{
rs = stmt.executeQuery("select * from GLYB where 用户名 ='" + user + "' AND 密码='" + pass + "'");
if (rs.next())
{
SXLMS frame=new SXLMS();
setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null, "用户不存在!");
textField1.setText("");
textField2.setText("");
}
}
catch (Exception eg) {
eg.printStackTrace();
}
}
else
{
try{
rs = stmt.executeQuery("select * from CJGLYB where 用户名='" + user + "' AND 密码='" + pass + "'");
if (rs.next())
{
LMS frame=new LMS();
setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null, "用户不存在!");
textField1.setText("");
textField2.setText("");
}
}
catch (Exception eg) {
eg.printStackTrace();
}
}
}
if(str.equals("取消"))
{
System.exit(0);
}
}
public void itemStateChanged(ItemEvent e)
{
if(choice1.getSelectedIndex()==1)
{
n=1;
}
else
{
n=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -