📄 70a48742b8f3001c1ba5970dd0539ecd
字号:
///////ok
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class DengLuFrame extends JFrame implements ActionListener{
JLabel label1 = new JLabel("用户名");
JLabel label2=new JLabel("密码");
JTextField textField1 = new JTextField();
JPasswordField textField2=new JPasswordField();
JButton button1 = new JButton("确定");
JButton button2 = new JButton("取消");
Connection conn;
Statement stmt;
ResultSet rs;
String strurl;
DengLuFrame() throws Exception
{
super("登陆窗口");
Container con = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.BLUE);
//setLayout(null);///////////////////////
JPanel panel = new JPanel();
panel.add(button1);
panel.add(button2);
Box box1, box2, box3, box;
box1 = Box.createVerticalBox();
box1.add(label1);
box1.add(Box.createVerticalStrut(18));
box1.add(label2);
box2 = Box.createVerticalBox();
box2.add(Box.createVerticalStrut(18));
box2.add(textField1);
box2.add(Box.createVerticalStrut(8));
box2.add(textField2);
box2.add(Box.createVerticalStrut(18));
box3 = Box.createHorizontalBox();
box3.add(Box.createHorizontalStrut(18));
box3.add(box1);
box3.add(Box.createHorizontalStrut(8));
box3.add(box2);
box3.add(Box.createHorizontalStrut(18));
box = Box.createVerticalBox();
box.add(box3);
box.add(panel);
box.add(Box.createVerticalStrut(8));
con.add(box);
setVisible(true);
setSize(300,200);
setLocationRelativeTo(null); //在桌面中点显示
validate();
/* 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:student";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
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 user,pass;
if (str.equals("确定"))
{
user=textField1.getText().trim();
String ee = new String(textField2.getPassword());
pass=ee;
try
{
rs = stmt.executeQuery("select * from STU where 用户名 ='" + user + "' AND 密码='" + pass + "'");
if (rs.next())
{
ZhuYMFrame zhuframe=new ZhuYMFrame();
setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null, "用户不存在!");
textField1.setText("");
textField2.setText("");
}
}
catch (Exception eg) {
eg.printStackTrace();
}
}
if(e.getSource()==button2)
{
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -