📄 denglu.java
字号:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;
import javax.swing.*;
public class Denglu {
static String[] ConnectOptionNames = { "登陆"," 退出" };
static JButton btn=new JButton("oi");
static String ConnectTitle = "登陆";
JDBCAdapter dataBase = new JDBCAdapter("jdbc:odbc:information",
"sun.jdbc.odbc.JdbcOdbcDriver", "", "");
JScrollPane tableAggregate;//滚动面板
User SystemUser;
JPanel connectionPanel;//?
JPasswordField passwordField=new JPasswordField("******");//密码文本框
JTextField userNameField=new JTextField("......");//名字文本框
JLabel userNameLabel;
JLabel passwordLabel;
public boolean activateConnectionDialog() {
if (JOptionPane.showOptionDialog(tableAggregate, connectionPanel,//?
ConnectTitle, JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null,ConnectOptionNames,
ConnectOptionNames[0]) == 0) {
if(!dataBase.executeQuery("select uid,uname,type from user where uid='"+userNameField.getText()
+"' and PassWord='"+passwordField.getText()+"'")){
JOptionPane.showMessageDialog(tableAggregate,"数据库操作失败","错误",JOptionPane.ERROR_MESSAGE,
new ImageIcon("image/caidanx.gif"));
return false;
}
Vector Vt = dataBase.GetVector();
if (Vt.isEmpty()) {
JOptionPane.showMessageDialog(tableAggregate, "用户名或密码错误", "提示",
JOptionPane.ERROR_MESSAGE, new ImageIcon(
"image/caidanx.gif"));
return false;
}else {
SystemUser = new User();
Vector newRow = (Vector) Vt.get(0);
SystemUser.setUserId(newRow.get(0).toString());
SystemUser.setUserName(newRow.get(1).toString());
}
// frame.setVisible(true);
return true;
}
else
{System.exit(0);
return false;
}
}
public void createConnectionDialog() {
// Create the labels and text fields.\
do{
userNameLabel = new JLabel("用户名: ", JLabel.LEFT);
userNameField = new JTextField("");
passwordLabel = new JLabel("密 码: ", JLabel.LEFT);
passwordField = new JPasswordField("");
connectionPanel = new JPanel();
connectionPanel.setLayout(new BoxLayout(connectionPanel,BoxLayout.X_AXIS)
);
//BoxLayout.X_AXIS BoxLayout(connectionPanel)
/*JPanel namePanel = new JPanel(false);
namePanel.setLayout(new GridLayout(1, 1));//设置两行一列
namePanel.add(userNameLabel);
namePanel.add(passwordLabel);*/
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(new GridLayout(4, 2));
fieldPanel.add(userNameLabel);
fieldPanel.add(userNameField);
fieldPanel.add(passwordLabel);
fieldPanel.add(passwordField);
/* addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {//?
//setVisible(false);
//dispose();
System.exit(0);
}
//public void windowStateChanged(WindowEvent e){}
});*/
connectionPanel.add(fieldPanel);
/*add(btn);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0); // TODO Auto-generated method stub
}
});*/
}while(!activateConnectionDialog());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -