📄 userlogindialog_1.java.svn-base
字号:
package collector.gui.view;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import collector.gui.guiVo.*;
public class UserLoginDialog_1
extends javax.swing.JDialog {
static ActiveUserClass activeUser;
private int m_option;
public UserLoginDialog_1(java.awt.Frame parent, boolean modal) {
super(parent, modal);
jbInit();
this.setTitle("用户登录");
String[] ChooseString = new String[] {
"5分钟", "15分钟", "30分钟", "1小时", "2小时", "4小时", "8小时", "无限时"};
timeCombo.setModel(new javax.swing.DefaultComboBoxModel(ChooseString));
timeCombo.setSelectedIndex(1);
timeCombo.setToolTipText("预置本用户持续活动时间");
userLabel.setText("请输入用户名: ");
passwordLabel.setText(" 请输入口令: ");
timeLabel.setText(" 请选择时长: ");
hintLabel.setText("请输入您的用户名!");
confirmButton.setText("确定");
cancelButton.setText("取消");
}
public ActiveUserClass getActiveUser() {
return activeUser;
}
private void jbInit() { //GEN-BEGIN:jbInit
jPanel1 = new javax.swing.JPanel();
userLabel = new javax.swing.JLabel();
userField = new javax.swing.JTextField();
passwordLabel = new javax.swing.JLabel();
passwordField = new javax.swing.JPasswordField();
timeLabel = new javax.swing.JLabel();
timeCombo = new javax.swing.JComboBox();
jPanel2 = new javax.swing.JPanel();
confirmButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
hintLabel = new javax.swing.JLabel();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
jPanel1.setLayout(new java.awt.GridLayout(3, 2));
jPanel1.setPreferredSize(new java.awt.Dimension(240, 100));
userLabel.setFont(new java.awt.Font("Dialog", 0, 12));
jPanel1.add(userLabel);
userField.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
userFieldFocusGained(evt);
}
});
jPanel1.add(userField);
passwordLabel.setFont(new java.awt.Font("Dialog", 0, 12));
jPanel1.add(passwordLabel);
passwordField.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
passwordFieldFocusGained(evt);
}
});
jPanel1.add(passwordField);
timeLabel.setFont(new java.awt.Font("Dialog", 0, 12));
jPanel1.add(timeLabel);
timeCombo.setBackground(new java.awt.Color(255, 255, 255));
timeCombo.setFont(new java.awt.Font("Dialog", 0, 12));
timeCombo.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
timeComboFocusGained(evt);
}
});
jPanel1.add(timeCombo);
getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
confirmButton.setFont(new java.awt.Font("Dialog", 0, 12));
confirmButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
confirmButtonMousePressed(evt);
}
});
jPanel2.add(confirmButton);
cancelButton.setFont(new java.awt.Font("Dialog", 0, 12));
cancelButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
cancelButtonMousePressed(evt);
}
});
jPanel2.add(cancelButton);
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
hintLabel.setFont(new java.awt.Font("Dialog", 0, 12));
hintLabel.setText(" ");
hintLabel.setBorder(new javax.swing.border.EtchedBorder());
hintLabel.setPreferredSize(new java.awt.Dimension(12, 12));
getContentPane().add(hintLabel, java.awt.BorderLayout.SOUTH);
pack();
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().
getScreenSize();
setSize(new java.awt.Dimension(254, 204));
setLocation( (screenSize.width - 254) / 2, (screenSize.height - 204) / 2);
} //GEN-END:jbInit
private void cancelButtonMousePressed(java.awt.event.MouseEvent evt) { //GEN-FIRST:event_cancelButtonMousePressed
closeDialog(null);
} //GEN-LAST:event_cancelButtonMousePressed
private void confirmButtonMousePressed(java.awt.event.MouseEvent evt) { //GEN-FIRST:event_confirmButtonMousePressed
int ts = timeCombo.getSelectedIndex();
String password = new String(passwordField.getPassword());
String userName = new String(userField.getText());
Date loginDate = new Date();
String[] periodTimes = {
"5", "15", "30", "60", "120", "240", "480", "14400000"};
long periodTime = Long.parseLong(periodTimes[ts]) * 60000;
Date expiredDate = new Date(loginDate.getTime() + periodTime);
closeDialog(null);
activeUser = new ActiveUserClass(userName, password, loginDate, expiredDate);
} //GEN-LAST:event_confirmButtonMousePressed
private void timeComboFocusGained(java.awt.event.FocusEvent evt) { //GEN-FIRST:event_timeComboFocusGained
hintLabel.setText("请选择时长!");
} //GEN-LAST:event_timeComboFocusGained
private void passwordFieldFocusGained(java.awt.event.FocusEvent evt) { //GEN-FIRST:event_passwordFieldFocusGained
hintLabel.setText("请输入您的密码!");
} //GEN-LAST:event_passwordFieldFocusGained
private void userFieldFocusGained(java.awt.event.FocusEvent evt) { //GEN-FIRST:event_userFieldFocusGained
hintLabel.setText("请输入您的用户名!");
} //GEN-LAST:event_userFieldFocusGained
private void closeDialog(java.awt.event.WindowEvent evt) { //GEN-FIRST:event_closeDialog
userField.setText("");
passwordField.setText("");
setVisible(false);
} //GEN-LAST:event_closeDialog
public int showDialog() {
m_option = JOptionPane.CANCEL_OPTION;
this.validate();
this.userField.requestFocus();
super.show();
return m_option;
}
public static void main(String args[]) {
new UserLoginDialog_1(new javax.swing.JFrame(), true).show();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel jPanel2;
private javax.swing.JPasswordField passwordField;
private javax.swing.JButton confirmButton;
private javax.swing.JLabel timeLabel;
private javax.swing.JLabel userLabel;
private javax.swing.JTextField userField;
private javax.swing.JButton cancelButton;
private javax.swing.JLabel hintLabel;
private javax.swing.JPanel jPanel1;
private javax.swing.JComboBox timeCombo;
private javax.swing.JLabel passwordLabel;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -