📄 userdialog.java
字号:
package train_table;import java.sql.*;import java.awt.*;import javax.swing.*;import javax.swing.border.*;import com.borland.jbcl.layout.*;import java.awt.event.*;import javax.swing.event.*;public class userDialog extends JDialog { // ImageIcon image=new ImageIcon("E:\\train_table\\THANKS8.gif"); // private borderLayout1 private XYLayout xYLayout1 = new XYLayout(); private Border border1; private JPanel jPanel1 = new JPanel(); private Border border2; private TitledBorder titledBorder1; private TitledBorder titledBorder2; private JPanel jPanel2 = new JPanel(); private XYLayout xYLayout2 = new XYLayout(); private TitledBorder titledBorder3; private JRadioButton jRadioButton1 = new JRadioButton(); private JRadioButton jRadioButton2 = new JRadioButton(); private JPanel jPanel3 = new JPanel(); private XYLayout xYLayout3 = new XYLayout(); private TitledBorder titledBorder4; private JLabel jLabel1 = new JLabel(); private JLabel jLabel2 = new JLabel(); private JTextField user_txt = new JTextField(); private JLabel jLabel3 = new JLabel(); private JRadioButton jRadioButton3 = new JRadioButton(); private JButton jButton1 = new JButton(); private TitledBorder titledBorder5; private TitledBorder titledBorder6; private JButton jButton3 = new JButton(); private JPasswordField yanzhen_txt = new JPasswordField(); private Border border3; private JPanel jPanel4 = new JPanel(); private TitledBorder titledBorder7; private JLabel jLabel4 = new JLabel(); private XYLayout xYLayout4 = new XYLayout(); private JLabel jLabel5 = new JLabel(); private JLabel jLabel6 = new JLabel(); private JPasswordField pswd_txt = new JPasswordField(); private JPanel jPanel5 = new JPanel(); private TitledBorder titledBorder8; private JLabel show_lbl = new JLabel(); private XYLayout xYLayout5 = new XYLayout(); public userDialog(Frame frame, String title, boolean modal) { super(frame, title, modal); try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } } public userDialog() { this(null, "", true); } private void jbInit() throws Exception { titledBorder8 = new TitledBorder(""); yanzhen_txt.setBackground(SystemColor.activeCaptionBorder); yanzhen_txt.setEnabled(false); border3 = BorderFactory.createLineBorder(Color.white,1); // jButton2.setIcon(image); border1 = BorderFactory.createLineBorder(Color.lightGray,1); border2 = BorderFactory.createLineBorder(SystemColor.inactiveCaptionBorder,1); titledBorder1 = new TitledBorder(""); titledBorder2 = new TitledBorder(""); titledBorder3 = new TitledBorder(""); titledBorder4 = new TitledBorder(""); titledBorder5 = new TitledBorder(""); titledBorder6 = new TitledBorder(""); titledBorder7 = new TitledBorder(""); this.getContentPane().setLayout(xYLayout1); jPanel1.setBorder(titledBorder2); jPanel1.setLayout(xYLayout2); jPanel2.setBorder(titledBorder3); jRadioButton1.setEnabled(false); jRadioButton1.setSelected(true); jRadioButton1.setText("添加用户"); jRadioButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jRadioButton1_actionPerformed(e); } }); jRadioButton2.setEnabled(false); jRadioButton2.setText("删除用户"); jRadioButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jRadioButton2_actionPerformed(e); } }); jPanel3.setLayout(xYLayout3); jPanel3.setBorder(titledBorder4); jLabel1.setText("用户名"); jLabel2.setText("密 码"); jLabel3.setText("验 证"); jRadioButton3.setEnabled(false); jRadioButton3.setText("密码修改"); jRadioButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jRadioButton3_actionPerformed(e); } }); jButton1.setText("进入"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); xYLayout1.setWidth(377); xYLayout1.setHeight(300); jButton3.setText("退出"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton3_actionPerformed(e); } }); yanzhen_txt.setEnabled(false); // yanzhen_txt.setDisabledTextColor(Color.lightGray); jPanel4.setBorder(titledBorder7); jPanel4.setLayout(xYLayout4); jLabel4.setText("1. 请输入用户和密码"); jLabel5.setText("2. 请点击进入"); jLabel6.setText("3. 核对正确方可正常编辑"); jPanel5.setBorder(titledBorder8); jPanel5.setLayout(xYLayout5); show_lbl.setForeground(Color.red); show_lbl.setHorizontalAlignment(SwingConstants.CENTER); this.getContentPane().add(jPanel1, new XYConstraints(22, 11, 336, 277)); jPanel2.add(jRadioButton1, null); jPanel2.add(jRadioButton2, null); jPanel2.add(jRadioButton3, null); jPanel1.add(jPanel4, new XYConstraints(122, 3, 193, 72)); jPanel4.add(jLabel4, new XYConstraints(14, 0, -1, -1)); jPanel4.add(jLabel6, new XYConstraints(14, 41, -1, -1)); jPanel4.add(jLabel5, new XYConstraints(14, 21, -1, -1)); jPanel1.add(jPanel5, new XYConstraints(122, 77, 193, 28)); jPanel5.add(show_lbl, new XYConstraints(0, 0, 184, 19)); jPanel1.add(jButton1, new XYConstraints(96, 231, -1, -1)); jPanel1.add(jButton3, new XYConstraints(155, 231, -1, -1)); jPanel1.add(jPanel3, new XYConstraints(7, 114, 309, 109)); jPanel3.add(jLabel1, new XYConstraints(48, 10, -1, -1)); jPanel3.add(user_txt, new XYConstraints(132, 6, 90, -1)); jPanel3.add(jLabel3, new XYConstraints(47, 73, -1, -1)); jPanel3.add(jLabel2, new XYConstraints(47, 42, -1, -1)); jPanel1.add(jPanel2, new XYConstraints(7, 3, 107, 104)); jPanel3.add(yanzhen_txt, new XYConstraints(133, 72, 91, -1)); jPanel3.add(pswd_txt, new XYConstraints(133, 40, 91, -1)); } void jButton1_actionPerformed(ActionEvent e) { errormessage em=new errormessage(); String s_user=user_txt.getText(); String s_pswd=pswd_txt.getText(); String s_yanz=yanzhen_txt.getText(); if(jButton1.getLabel().equals("进入")) //先实现管理员的登录 { dbBean db=new dbBean(); ResultSet rs=null; String sql="select admini from administartor where admini='"+s_user+"' and (select password from administartor where password='"+s_pswd+"' )"; try{ rs=db.executeQuery(sql); //查询合法管理员 if(!rs.next()) //判断管理员的合法性 { show_lbl.setText("对不起,您不是合法用户!"); user_txt.setText(""); pswd_txt.setText(""); } else{ //进入用户操作界面 show_lbl.setText("欢迎进入"); jButton1.setLabel("确定"); user_txt.setText(""); pswd_txt.setText(""); jRadioButton1.setEnabled(true); jRadioButton2.setEnabled(true); jRadioButton3.setEnabled(true); yanzhen_txt.setEnabled(true); yanzhen_txt.setBackground(Color.white); } } catch(Exception ee) {} } else if(jRadioButton1.isSelected()) //添加用户的处理 { dbBean DB=new dbBean(); ResultSet RS=null; String SQL1="select admini from administartor where admini='"+s_user+"'"; try{ RS=DB.executeQuery(SQL1); //查询用户是否重复 if(!RS.next()){ //当不重复时的处理 //处理密码范围为4--16位 if(em.isLength(4,16,s_pswd)&&!em.isEmpty(s_user)) { if(s_pswd.equals(s_yanz)) //密码的验证 { dbBean db=new dbBean(); String sql="insert into administartor (admini,password) values ('"+s_user+"','"+s_pswd+"')"; db.executeQuery(sql); //将信息提交数据库 show_lbl.setText("恭喜您!提交成功,成为新用户"); } else{ JOptionPane.showMessageDialog(null, "验证密码不符,请重新输入"); } } else{ JOptionPane.showMessageDialog(null, "用户不能为空,密码长度范围4--16位"); pswd_txt.setText(""); yanzhen_txt.setText(""); } } else{ JOptionPane.showMessageDialog(null, "此用户已经存在若更改密码请直接选择更改密码项"); user_txt.setText(""); } } catch(Exception ie){} } else if(jRadioButton2.isSelected()) //用户的删除 { dbBean db=new dbBean(); ResultSet rs=null; String sql="select admini from administartor where admini='"+user_txt.getText()+"' and (select password from administartor where password='"+pswd_txt.getText()+"' )"; try{ rs=db.executeQuery(sql); //核查用户的合法性 if(!rs.next()) { JOptionPane.showMessageDialog(null, "对不起,您不是合法用户!"); user_txt.setText(""); pswd_txt.setText(""); } else{ String SQL2="delete from administartor where admini='"+user_txt.getText()+"'"; db.executeQuery(SQL2); //执行删除用户 user_txt.setText(""); pswd_txt.setText(""); show_lbl.setText("此用户以被清除"); } } catch(Exception ii) {} } else{ //密码的修改 dbBean db=new dbBean(); ResultSet rs=null; String sql="select admini from administartor where admini='"+user_txt.getText()+"'"; try{ rs=db.executeQuery(sql); //检查用户的合法性 if(rs.next()) { if(em.isLength(4,16,s_pswd)&&!em.isEmpty(s_user)){ if(s_pswd.equals(s_yanz)) { String sql2="update administartor set password="+s_pswd+" where admini='"+s_user+"'"; db.executeQuery(sql2); //执行密码修改并更新数据库 show_lbl.setText("密码修改成功!"); } else {show_lbl.setText("密码验证错误"); } }else{ JOptionPane.showMessageDialog(null, "用户不能为空,密码长度范围4--16位"); pswd_txt.setText(""); yanzhen_txt.setText(""); } } else{ show_lbl.setText("此用户不存在!"); } } catch(Exception iii){} }} void jButton3_actionPerformed(ActionEvent e) { this.dispose(); //退出 } //删除用户的选择按钮的初始化 void jRadioButton2_actionPerformed(ActionEvent e) { user_txt.setText(""); pswd_txt.setText(""); yanzhen_txt.setText(""); jRadioButton1.setSelected(false); jRadioButton3.setSelected(false); yanzhen_txt.setBackground(SystemColor.activeCaptionBorder); yanzhen_txt.setEnabled(false); } //添加用户的选择按钮的初始化 void jRadioButton1_actionPerformed(ActionEvent e) { yanzhen_txt.setBackground(Color.white); yanzhen_txt.setEnabled(true); user_txt.setText(""); pswd_txt.setText(""); yanzhen_txt.setText(""); jRadioButton2.setSelected(false); jRadioButton3.setSelected(false); } //修改密码选择按钮的初始化 void jRadioButton3_actionPerformed(ActionEvent e) { yanzhen_txt.setBackground(Color.white); yanzhen_txt.setEnabled(true); user_txt.setText(""); pswd_txt.setText(""); yanzhen_txt.setText(""); jRadioButton1.setSelected(false); jRadioButton2.setSelected(false); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -