JF_user_add.java
上传用户:whbcdz
上传日期:2008-08-04
资源大小:7683k
文件大小:11k
源码类别:

JavaScript

开发平台:

Java

  1. package appjxc.view;
  2. import java.awt.BorderLayout;
  3. import javax.swing.JFrame;
  4. import javax.swing.JSplitPane;
  5. import javax.swing.JScrollPane;
  6. import javax.swing.JPanel;
  7. import java.awt.GridLayout;
  8. import javax.swing.JLabel;
  9. import javax.swing.JTextField;
  10. import javax.swing.JTable;
  11. import javax.swing.*;
  12. import java.awt.Font;
  13. import java.awt.FlowLayout;
  14. import javax.swing.table.DefaultTableModel;
  15. import appjxc.constrol.JTkeyAdapter;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.awt.event.KeyEvent;
  19. import java.awt.event.KeyAdapter;
  20. public class JF_user_add extends javax.swing.JInternalFrame{//JFrame {
  21.     BorderLayout borderLayout1 = new BorderLayout();
  22.     JPanel jPanel2 = new JPanel();
  23.     FlowLayout flowLayout1 = new FlowLayout();
  24.     JButton jBadd = new JButton();
  25.     JButton jBsave = new JButton();
  26.     JButton jBexit = new JButton();
  27.     javax.sql.DataSource ds = null;
  28.     java.sql.Connection con = null;
  29.     java.sql.Statement stmt = null;
  30.     java.sql.ResultSet rs = null;
  31.     DefaultTableModel defaultModel = null;
  32.     JPanel jPanel1 = new JPanel();
  33.     GridLayout gridLayout1 = new GridLayout();
  34.     JLabel jLabel1 = new JLabel();
  35.     JTextField jTid = new JTextField();
  36.     JLabel jLabel2 = new JLabel();
  37.     JTextField jTname = new JTextField();
  38.     JLabel jLabel3 = new JLabel();
  39.     JPasswordField jPass = new JPasswordField();
  40.     JLabel jLabel4 = new JLabel();
  41.     JPasswordField jPassconf = new JPasswordField();
  42.     public JF_user_add() {
  43.         try {
  44.             jbInit();
  45.             jTid.setText("");
  46.             jTid.requestFocus();
  47.             jTname.addKeyListener(new JTkeyAdapter((JTextField)jPass));
  48.             jPass.addKeyListener(new JTkeyAdapter(jPassconf));
  49.            // buildeTable();
  50.         } catch (Exception exception) {
  51.             exception.printStackTrace();
  52.         }
  53.     }
  54.     public String getID(){
  55.         String maxid = "",newid = "";
  56.         String queryStr = "select max(userid) as id from Obj_UserName";
  57.         java.util.List list = appjxc.dao.AdapterDao.QueryObject(queryStr);
  58.         if (list.size() > 0 ){
  59.          maxid = String.valueOf(list.get(0));
  60.          newid = String.valueOf(Integer.parseInt(maxid) + 1);
  61.         }
  62.         return newid;
  63.     }
  64.     public void buildeTable(){
  65.         java.util.Vector vname = new java.util.Vector();
  66.         vname.addElement("用户ID");
  67.         vname.addElement("用户姓名");
  68.         vname.addElement("用户口令");
  69.         vname.addElement("重复口令");
  70.         defaultModel = new DefaultTableModel(vname,0);
  71.         ds = null;
  72.         try{
  73.             con = ds.getConnection();
  74.             stmt = con.createStatement();
  75.             stmt.execute("select * from t_user");
  76.             rs = stmt.getResultSet();
  77.             while(rs.next()){
  78.                 java.util.Vector vdata = new java.util.Vector();
  79.                 vdata.addElement(rs.getString("id").trim());
  80.                 vdata.addElement(rs.getString("name").trim());
  81.                 vdata.addElement(rs.getString("pass").trim());
  82.                 vdata.addElement(rs.getString("passconf").trim());
  83.                 defaultModel.addRow(vdata);
  84.             }
  85.             con.close();
  86.         }catch(java.sql.SQLException sql){
  87.             sql.printStackTrace();
  88.         }
  89.     }
  90.     private void jbInit() throws Exception {
  91.         getContentPane().setLayout(borderLayout1);
  92.         jPanel2.setLayout(flowLayout1);
  93.         jBadd.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  94.         jBadd.setText("增加");
  95.         jBadd.addActionListener(new JF_user_add_jBadd_actionAdapter(this));
  96.         jBsave.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  97.         jBsave.setText("存盘");
  98.         jBsave.addActionListener(new JF_user_add_jBsave_actionAdapter(this));
  99.         jBexit.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  100.         jBexit.setText("退出");
  101.         jBexit.addActionListener(new JF_user_add_jBexit_actionAdapter(this));
  102.         flowLayout1.setAlignment(FlowLayout.RIGHT);
  103.         jPanel1.setLayout(gridLayout1);
  104.         gridLayout1.setColumns(4);
  105.         gridLayout1.setRows(2);
  106.         jLabel1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  107.         jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
  108.         jLabel1.setText("用户ID");
  109.         jTid.setText("");
  110.         jTid.addKeyListener(new JF_user_add_jTid_keyAdapter(this));
  111.         jLabel2.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  112.         jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
  113.         jLabel2.setText("用户姓名");
  114.         jTname.setText("");
  115.         jLabel3.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  116.         jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
  117.         jLabel3.setText("用户口令");
  118.         jPass.setText("");
  119.         jLabel4.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  120.         jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
  121.         jLabel4.setText("重复口令");
  122.         jPassconf.setText("");
  123.         this.setClosable(true);
  124.         this.setTitle("用户添加信息管理");
  125.         this.getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
  126.         jPanel2.add(jBadd);
  127.         jPanel2.add(jBsave);
  128.         jPanel2.add(jBexit);
  129.         this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
  130.         jPanel1.add(jLabel1);
  131.         jPanel1.add(jTid);
  132.         jPanel1.add(jLabel2);
  133.         jPanel1.add(jTname);
  134.         jPanel1.add(jLabel3);
  135.         jPanel1.add(jPass);
  136.         jPanel1.add(jLabel4);
  137.         jPanel1.add(jPassconf);
  138.         this.setBounds(50,50,400,120);
  139.         this.setVisible(true);
  140.     }
  141.     public static void main(String[] args) {
  142.         JF_user_add jf_user_add = new JF_user_add();
  143.     }
  144.     public void jBadd_actionPerformed(ActionEvent actionEvent) {
  145.         //jTid.setText(this.getID());
  146.         jTid.setText("");
  147.         jTname.setText("");
  148.         jPass.setText("");
  149.         jPassconf.setText("");
  150.         jTname.requestFocus();
  151.         jBsave.setEnabled(true);
  152.     }
  153.     public void jBsave_actionPerformed(ActionEvent actionEvent) {
  154.         int result = JOptionPane.showOptionDialog(null,"是否增加新的用户信息?","系统提示",
  155.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  156.                                    null,new String[]  {"是","否"},"否");
  157.         if (result == JOptionPane.NO_OPTION) return;
  158.         if (jTid.getText().trim().length() <= 0){
  159.             JOptionPane.showMessageDialog(null, "用户ID不允许为空,请录入!!!", "系统提示",
  160.                                                   JOptionPane.ERROR_MESSAGE);
  161.             jTid.requestFocus();
  162.             return;
  163.         }
  164.         if (jTname.getText().trim().length() <= 0){
  165.             JOptionPane.showMessageDialog(null, "用户姓名不允许为空,请录入!!!", "系统提示",
  166.                                                   JOptionPane.ERROR_MESSAGE);
  167.             jTname.requestFocus();
  168.             return;
  169.         }
  170.         if (jPass.getPassword().toString().trim().length() <= 0){
  171.             JOptionPane.showMessageDialog(null, "用户口令不允许为空,请录入!!!", "系统提示",
  172.                                                   JOptionPane.ERROR_MESSAGE);
  173.             jPass.requestFocus();
  174.             return;
  175.         }
  176.         if (jPassconf.getPassword().toString().trim().length() <= 0){
  177.             JOptionPane.showMessageDialog(null, "重复口令不允许为空,请录入!!!", "系统提示",
  178.                                                   JOptionPane.ERROR_MESSAGE);
  179.             jPassconf.requestFocus();
  180.             return;
  181.         }
  182.         String password,password1;
  183.         password = new String(jPass.getPassword());
  184.         password1 = new String(jPassconf.getPassword());
  185.        // System.out.println(password + ":" + password1);
  186.         if (!(password.equals(password1))){
  187.             JOptionPane.showMessageDialog(null, "输入的两次口令不一致,请重新录入!!!", "系统提示",
  188.                                                   JOptionPane.ERROR_MESSAGE);
  189.             jPassconf.requestFocus();
  190.             return;
  191.         }
  192.          String id,user,pass,passconf;
  193.          id = jTid.getText().trim();
  194.          user = jTname.getText().trim();
  195.          pass = String.valueOf(jPass.getPassword());
  196.          passconf = String.valueOf(jPassconf.getPassword());
  197.          appjxc.model.Obj_UserName objuser = new appjxc.model.Obj_UserName();
  198.          objuser.setUserid(id);
  199.          objuser.setUsername(user);
  200.          objuser.setPassword(pass);
  201.          objuser.setPassconf(passconf);
  202.          appjxc.dao.AdapterDao.InsertObj_UserName(objuser);
  203.          JOptionPane.showMessageDialog(null, "该用户添加成功!!!", "系统提示",
  204.                                                  JOptionPane.INFORMATION_MESSAGE);
  205.     }
  206.     public void jBexit_actionPerformed(ActionEvent actionEvent) {
  207.         javax.swing.DefaultDesktopManager manger = new DefaultDesktopManager();
  208.         int result = JOptionPane.showOptionDialog(null,"是否退出用户增加模块?","系统提示",
  209.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  210.                                    null,new String[]  {"是","否"},"否");
  211.         if (result == JOptionPane.YES_OPTION) {
  212.            manger.closeFrame(this);
  213.         }
  214.     }
  215.     public void jTid_keyPressed(KeyEvent keyEvent) {
  216.         if(keyEvent.getKeyCode() == KeyEvent.VK_ENTER){
  217.             String userid = jTid.getText().trim();
  218.             String queryStr = " from Obj_UserName where userid = '" + userid + "'";
  219.             java.util.List list = appjxc.dao.AdapterDao.QueryObject(queryStr);
  220.             java.util.Iterator iterator = list.iterator();
  221.             if (iterator.hasNext()){
  222.                 JOptionPane.showMessageDialog(null,"用户ID已经存在请重新输入!!","系统提示",JOptionPane.ERROR_MESSAGE);
  223.                 jTid.requestFocus();
  224.                 return;
  225.             }
  226.             jTname.requestFocus();
  227.         }
  228.     }
  229. }
  230. class JF_user_add_jTid_keyAdapter extends KeyAdapter {
  231.     private JF_user_add adaptee;
  232.     JF_user_add_jTid_keyAdapter(JF_user_add adaptee) {
  233.         this.adaptee = adaptee;
  234.     }
  235.     public void keyPressed(KeyEvent keyEvent) {
  236.         adaptee.jTid_keyPressed(keyEvent);
  237.     }
  238. }
  239. class JF_user_add_jBexit_actionAdapter implements ActionListener {
  240.     private JF_user_add adaptee;
  241.     JF_user_add_jBexit_actionAdapter(JF_user_add adaptee) {
  242.         this.adaptee = adaptee;
  243.     }
  244.     public void actionPerformed(ActionEvent actionEvent) {
  245.         adaptee.jBexit_actionPerformed(actionEvent);
  246.     }
  247. }
  248. class JF_user_add_jBsave_actionAdapter implements ActionListener {
  249.     private JF_user_add adaptee;
  250.     JF_user_add_jBsave_actionAdapter(JF_user_add adaptee) {
  251.         this.adaptee = adaptee;
  252.     }
  253.     public void actionPerformed(ActionEvent actionEvent) {
  254.         adaptee.jBsave_actionPerformed(actionEvent);
  255.     }
  256. }
  257. class JF_user_add_jBadd_actionAdapter implements ActionListener {
  258.     private JF_user_add adaptee;
  259.     JF_user_add_jBadd_actionAdapter(JF_user_add adaptee) {
  260.         this.adaptee = adaptee;
  261.     }
  262.     public void actionPerformed(ActionEvent actionEvent) {
  263.         adaptee.jBadd_actionPerformed(actionEvent);
  264.     }
  265. }