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

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 java.awt.event.ActionEvent;
  16. import java.awt.event.ActionListener;
  17. import java.awt.event.MouseEvent;
  18. import java.awt.event.MouseAdapter;
  19. public class JF_user_modi extends javax.swing.JInternalFrame{//JFrame {
  20.     BorderLayout borderLayout1 = new BorderLayout();
  21.     JSplitPane jSplitPane1 = new JSplitPane();
  22.     JScrollPane jScrollPane1 = new JScrollPane();
  23.     JPanel jPanel1 = new JPanel();
  24.     GridLayout gridLayout1 = new GridLayout();
  25.     JLabel jLabel1 = new JLabel();
  26.     JTextField jTid = new JTextField();
  27.     JLabel jLabel2 = new JLabel();
  28.     JLabel jLabel3 = new JLabel();
  29.     JTextField jTname = new JTextField();
  30.     JLabel jLabel4 = new JLabel();
  31.     JTable jTable1 = new JTable();
  32.     JPanel jPanel2 = new JPanel();
  33.     FlowLayout flowLayout1 = new FlowLayout();
  34.     JButton jBsave = new JButton();
  35.     JButton jBexit = new JButton();
  36.     javax.sql.DataSource ds = null;
  37.     java.sql.Connection con = null;
  38.     java.sql.Statement stmt = null;
  39.     java.sql.ResultSet rs = null;
  40.     DefaultTableModel defaultModel = null;
  41.     JPasswordField jPass = new JPasswordField();
  42.     JPasswordField jPassconf = new JPasswordField();
  43.     JButton jBdel = new JButton();
  44.     public JF_user_modi() {
  45.         try {
  46.             jbInit();
  47.             buildeTable();
  48.         } catch (Exception exception) {
  49.             exception.printStackTrace();
  50.         }
  51.     }
  52.     private void buildeTable(){
  53.         java.util.Vector vname = new java.util.Vector();
  54.         vname.addElement("用户ID");
  55.         vname.addElement("用户姓名");
  56.         vname.addElement("用户口令");
  57.         vname.addElement("重复口令");
  58.         defaultModel = new DefaultTableModel(vname,0);
  59.         String queryStr = " from Obj_UserName ";
  60.         java.util.List list = appjxc.dao.AdapterDao.QueryObject(queryStr);
  61.         java.util.Iterator iterator = list.iterator();
  62.         while(iterator.hasNext()){
  63.             appjxc.model.Obj_UserName objuser = (appjxc.model.Obj_UserName)iterator.next();
  64.             java.util.Vector vdata = new java.util.Vector();
  65.             vdata.addElement(objuser.getUserid());
  66.             vdata.addElement(objuser.getUsername());
  67.             vdata.addElement(objuser.getPassword());
  68.             vdata.addElement(objuser.getPassconf());
  69.             defaultModel.addRow(vdata);
  70.         }
  71.         jTable1.setModel(defaultModel);
  72.         jTable1.setRowHeight(24);
  73.     }
  74.     private void jbInit() throws Exception {
  75.         getContentPane().setLayout(borderLayout1);
  76.         jLabel1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  77.         jLabel1.setToolTipText("");
  78.         jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
  79.         jLabel3.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  80.         jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
  81.         jLabel2.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  82.         jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
  83.         jLabel4.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  84.         jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
  85.         jPanel2.setLayout(flowLayout1);
  86.         jBsave.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  87.         jBsave.setText("存盘");
  88.         jBsave.addActionListener(new JF_user_modi_jBsave_actionAdapter(this));
  89.         jBexit.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  90.         jBexit.setText("退出");
  91.         jBexit.addActionListener(new JF_user_modi_jBexit_actionAdapter(this));
  92.         flowLayout1.setAlignment(FlowLayout.RIGHT);
  93.         this.setClosable(true);
  94.         this.setTitle("用户维护");
  95.         jPass.setText("");
  96.         jPassconf.setText("");
  97.         jTable1.addMouseListener(new JF_user_modi_jTable1_mouseAdapter(this));
  98.         jBdel.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  99.         jBdel.setText("删除");
  100.         jBdel.addActionListener(new JF_user_modi_jBdel_actionAdapter(this));
  101.         this.getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);
  102.         jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
  103.         jPanel1.setLayout(gridLayout1);
  104.         gridLayout1.setColumns(4);
  105.         gridLayout1.setRows(2);
  106.         jLabel1.setText("用户ID");
  107.         jTid.setText("");
  108.         jLabel2.setText("用户口令");
  109.         jLabel3.setText("用户姓名");
  110.         jTname.setText("");
  111.         jLabel4.setText("重复口令");
  112.         jSplitPane1.add(jScrollPane1, JSplitPane.TOP);
  113.         jSplitPane1.add(jPanel1, JSplitPane.BOTTOM);
  114.         jPanel1.add(jLabel1);
  115.         jPanel1.add(jTid);
  116.         jPanel1.add(jLabel3);
  117.         jPanel1.add(jTname);
  118.         jPanel1.add(jLabel2);
  119.         jPanel1.add(jPass);
  120.         jPanel1.add(jLabel4);
  121.         jPanel1.add(jPassconf);
  122.         jScrollPane1.getViewport().add(jTable1);
  123.         this.getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
  124.         jPanel2.add(jBsave);
  125.         jPanel2.add(jBdel);
  126.         jPanel2.add(jBexit);
  127.         jSplitPane1.setDividerLocation(120);
  128.         jBsave.setEnabled(false);
  129.         this.setBounds(50,50,400,250);
  130.         this.setVisible(true);
  131.     }
  132.     public static void main(String[] args) {
  133.         JF_user_modi jf_user_add = new JF_user_modi();
  134.     }
  135.     public void jBsave_actionPerformed(ActionEvent actionEvent) {
  136.         int result = JOptionPane.showOptionDialog(null,"是否修改用户信息?","系统提示",
  137.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  138.                                    null,new String[]  {"是","否"},"否");
  139.         if (result == JOptionPane.NO_OPTION) return;
  140.         String password,password1;
  141.         password = new String(jPass.getPassword());
  142.         password1 = new String(jPassconf.getPassword());
  143.        // System.out.println(password + ":" + password1);
  144.         if (!(password.equals(password1))){
  145.             JOptionPane.showMessageDialog(null, "输入的两次口令不一致,请重新录入!!!", "系统提示",
  146.                                                   JOptionPane.ERROR_MESSAGE);
  147.             jPassconf.requestFocus();
  148.             return;
  149.         }
  150.         String id,user,pass,passconf;
  151.         id = jTid.getText().trim().trim();
  152.         user = jTname.getText().trim().trim();
  153.         pass = String.valueOf(jPass.getPassword()).trim();
  154.         passconf = String.valueOf(jPassconf.getPassword()).trim();
  155.         appjxc.model.Obj_UserName objuser = new appjxc.model.Obj_UserName();
  156.         objuser.setUserid(id);
  157.         objuser.setUsername(user);
  158.         objuser.setPassword(pass);
  159.         objuser.setPassconf(passconf);
  160.         appjxc.dao.AdapterDao.InsertObj_UserName(objuser);
  161.         JOptionPane.showMessageDialog(null, "该用户数据更新成功!!!", "系统提示",
  162.                                       JOptionPane.INFORMATION_MESSAGE);
  163.         this.buildeTable();
  164.             //jBsave.setEnabled(false);
  165.     }
  166.     public void jBexit_actionPerformed(ActionEvent actionEvent) {
  167.         javax.swing.DefaultDesktopManager manger = new DefaultDesktopManager();
  168.         int result = JOptionPane.showOptionDialog(null,"是否退出用户维护?","系统提示",
  169.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  170.                                    null,new String[]  {"是","否"},"否");
  171.         if (result == JOptionPane.YES_OPTION) {
  172.            manger.closeFrame(this);
  173.         }
  174.     }
  175.     public void jTable1_mousePressed(MouseEvent mouseEvent) {
  176.         String id,name,pass,pass1;
  177.         int row ;
  178.         row = jTable1.getSelectedRow();
  179.         id = jTable1.getValueAt(row,0).toString();
  180.         name = jTable1.getValueAt(row,1).toString();
  181.         pass = jTable1.getValueAt(row,2).toString();
  182.         pass1 = jTable1.getValueAt(row,3).toString();
  183.         jTid.setText(id);
  184.         jTname.setText(name);
  185.         jPass.setText(pass);
  186.         jPassconf.setText(pass1);
  187.         jBsave.setEnabled(true);
  188.     }
  189.     public void jBdel_actionPerformed(ActionEvent e) {
  190.         int result = JOptionPane.showOptionDialog(null,"是否删除用户" + jTid.getText()+ "?","系统提示",
  191.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  192.                                    null,new String[]  {"是","否"},"否");
  193.         if (result == JOptionPane.NO_OPTION) return;
  194.          appjxc.model.Obj_UserName objuser = new appjxc.model.Obj_UserName();
  195.          objuser.setUserid(jTid.getText().trim());
  196.          objuser.setUsername(jTname.getText().trim());
  197.          appjxc.dao.AdapterDao.DeleteUser(objuser);
  198.          JOptionPane.showMessageDialog(null, "该用户数据删除成功!!!", "系统提示",
  199.                                        JOptionPane.INFORMATION_MESSAGE);
  200.          this.buildeTable();
  201.          jTid.setText("");
  202.         jTname.setText("");
  203.         jPass.setText("");
  204.         jPassconf.setText("");
  205.     }
  206. }
  207. class JF_user_modi_jBdel_actionAdapter implements ActionListener {
  208.     private JF_user_modi adaptee;
  209.     JF_user_modi_jBdel_actionAdapter(JF_user_modi adaptee) {
  210.         this.adaptee = adaptee;
  211.     }
  212.     public void actionPerformed(ActionEvent e) {
  213.         adaptee.jBdel_actionPerformed(e);
  214.     }
  215. }
  216. class JF_user_modi_jTable1_mouseAdapter extends MouseAdapter {
  217.     private JF_user_modi adaptee;
  218.     JF_user_modi_jTable1_mouseAdapter(JF_user_modi adaptee) {
  219.         this.adaptee = adaptee;
  220.     }
  221.     public void mousePressed(MouseEvent mouseEvent) {
  222.         adaptee.jTable1_mousePressed(mouseEvent);
  223.     }
  224. }
  225. class JF_user_modi_jBexit_actionAdapter implements ActionListener {
  226.     private JF_user_modi adaptee;
  227.     JF_user_modi_jBexit_actionAdapter(JF_user_modi adaptee) {
  228.         this.adaptee = adaptee;
  229.     }
  230.     public void actionPerformed(ActionEvent actionEvent) {
  231.         adaptee.jBexit_actionPerformed(actionEvent);
  232.     }
  233. }
  234. class JF_user_modi_jBsave_actionAdapter implements ActionListener {
  235.     private JF_user_modi adaptee;
  236.     JF_user_modi_jBsave_actionAdapter(JF_user_modi adaptee) {
  237.         this.adaptee = adaptee;
  238.     }
  239.     public void actionPerformed(ActionEvent actionEvent) {
  240.         adaptee.jBsave_actionPerformed(actionEvent);
  241.     }
  242. }