📄 debarkationdialog.java
字号:
package stage_project;
import java.awt.BorderLayout;
import java.awt.Frame;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import java.text.*;
import java.util.Date;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class DebarkationDialog extends JDialog {
JPanel panel1 = new JPanel();
ImageIcon img = new ImageIcon("denglu2.gif");
JLabel lblBeijing = new JLabel(img);
JTextField txtName = new JTextField();
JPasswordField pwd = new JPasswordField();
JButton btnOk = new JButton();
JButton btnChongzhi = new JButton();
ImageIcon img2 = new ImageIcon("loginbtnico.gif");
JLabel lblDenglu = new JLabel(img2);
//设置开始时间为默认当前时间
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String sj = df.format(new Date());
static String name;
public DebarkationDialog(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public DebarkationDialog() {
this(new Frame(), "登 陆", false);
}
private void jbInit() throws Exception {
panel1.setLayout(null);
lblBeijing.setBackground(UIManager.getColor(
"InternalFrame.inactiveTitleForeground"));
lblBeijing.setText("");
lblBeijing.setBounds(new Rectangle(0, 0, 400, 250));
txtName.setText("");
txtName.setBounds(new Rectangle(237, 107, 115, 23));
pwd.setText("");
pwd.setBounds(new Rectangle(237, 147, 115, 23));
btnOk.setBackground(Color.white);
btnOk.setBounds(new Rectangle(172, 189, 70, 25));
btnOk.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
btnOk.setForeground(new Color(101, 155, 196));
btnOk.setText("登 陆");
btnOk.addActionListener(new DebarkationDialog_btnOk_actionAdapter(this));
btnChongzhi.setBackground(Color.white);
btnChongzhi.setBounds(new Rectangle(281, 189, 70, 25));
btnChongzhi.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
btnChongzhi.setForeground(new Color(101, 155, 196));
btnChongzhi.setText("重 置");
btnChongzhi.addActionListener(new
DebarkationDialog_btnChongzhi_actionAdapter(this));
lblDenglu.setText("");
lblDenglu.setBounds(new Rectangle(174, 191, 65, 23));
getContentPane().add(panel1);
panel1.add(txtName);
panel1.add(pwd);
panel1.add(btnOk);
panel1.add(btnChongzhi);
panel1.add(lblDenglu);
panel1.add(lblBeijing);
}
//管理员登陆按钮事件
public void btnOk_actionPerformed(ActionEvent e) {
//得到用户输入的值
name = txtName.getText();
char[] c = pwd.getPassword();
String pwd = new String(c);
//验证输入是否有效
if (name.equals("")) {
JOptionPane.showMessageDialog(this, "请输入用户名");
return;
} else if (pwd.equals("")) {
JOptionPane.showMessageDialog(this, "请输入密码");
return;
}
//拼接SQL语句
String sql = "select * from operator where name='" + name +
"' and pwd='" +
pwd + "'";
//调用数据库的方法
DBAccess db = new DBAccess();
boolean bn = db.jiancha(sql);
if (bn) {
String updatesql = "update operator set LoginTime='" + sj +
"' where name='" + name + "'and pwd='" +
pwd + "'";
db.doUpdate(updatesql);
MainbodyFrame frame = new MainbodyFrame();
frame.setLocation(0, 0);
frame.setSize(960, 650);
// Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "用户名或密码无效");
return;
}
}
//重置事件处理
public void btnChongzhi_actionPerformed(ActionEvent e) {
txtName.setText("");
pwd.setText("");
}
}
class DebarkationDialog_btnChongzhi_actionAdapter implements ActionListener {
private DebarkationDialog adaptee;
DebarkationDialog_btnChongzhi_actionAdapter(DebarkationDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnChongzhi_actionPerformed(e);
}
}
class DebarkationDialog_btnOk_actionAdapter implements ActionListener {
private DebarkationDialog adaptee;
DebarkationDialog_btnOk_actionAdapter(DebarkationDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnOk_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -