TXT

java

By Gene Mitchell,2014-05-26 13:04
4 views 0
java

import java.awt.Container;

    import java.awt.Component;

    import java.awt.Graphics;

    import java.awt.Graphics2D;

    import java.awt.Image;

    import java.awt.Toolkit;

    import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.sql.Statement;

    import java.util.Vector;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    import javax.swing.JLabel; //?ÉÒÔÏÔÊ?ÎÄ????Í?Ïñ?òÍ?Ê?ÏÔÊ??þÕß

    import javax.swing.JOptionPane;

    import javax.swing.JPanel;

    import javax.swing.JRadioButton;

    import javax.swing.JScrollPane;

    import javax.swing.JTable;

    import javax.swing.JTextArea;

    import javax.swing.JTextField; //ÇáÁ???×é?þ??ËüÔÊÐí?à??µ?ÐÐÎÄ????

    import javax.swing.table.TableCellRenderer;

public class jiemian {

     JFrame jf,j,jb;//jf ÊǵÇÂ????ÚµÄ?ÔÏó??jb ÊÇ×??á???ÚµÄ?ÔÏó??jÊÇÁÐ?í???ÚµÄ?ÔÏó

     JButton deng, zhuce,biaj, shc, xig, fh,chongzhi, fanhui;

     Vector rowData, columnName;

     JLabel userNameLabel, passWordLabel,namelabel, mimalabel, nilabel,

    minglabel, nianlabel, xinglabel,

     dianlabel, zhuanlabel, zhuzhilabel, qitalabel;

     //TextArea qitaText;

     JTextField userName, password,nameField, mimaField, niField,

    mingField, nianField, xingField,

     dianField, zhuanField, zhuzhiField;

     JTable jie;

     JTextArea qita;

     public jiemian() {

     kuang();

     }

     class MyPanel extends JPanel {

     public void paintComponent(Graphics g) {

     Graphics2D g2 = (Graphics2D) g;

     super.paintComponent(g);

     Image img = Toolkit.getDefaultToolkit().getImage(

     "image\\beijing.jpg");

     g2.drawImage(img, 0, 0, this.getWidth(), this.getHeight(),

    this);

     }

     }

     public void kuang() {

     jf = new JFrame();

     jf.setContentPane(new MyPanel()); // ????Í?

     deng = new JButton("µÇ Â?");

     zhuce = new JButton("×??á");

     userNameLabel = new JLabel("ÓÃ??Ãû:");

     passWordLabel = new JLabel("ÃÜ Âë:");

     userName = new JTextField();

     password = new JTextField();

     // new xuhao();

     jf.setSize(380, 300);

     jf.setLocation(500, 200); // Î?ÖÃ

     // ContentPaneΪ JWindow µÄËùÓÐ×Ó???ÚµÄ?????Ú ??JWindow

    ÊÇÒ??öÈÝÆ????ÉÒÔÏÔÊ?ÔÚÓÃ??×ÀÃæÉϵÄÈκÎÎ?ÖÃ

     Container ctDengLu = jf.getContentPane(); // getContentPane()???? ?µ?Ø

     ctDengLu.setLayout(null); // ÉèÖÃ LayoutManager??

     userNameLabel.setBounds(80, 120, 80, 30);

     ctDengLu.add(userNameLabel);

     // jf.setUndecorated(true); //È??ýÍâ?ò

     passWordLabel.setBounds(80, 150, 80, 30);

     ctDengLu.add(passWordLabel);

     passWordLabel.setOpaque(false);

     userName.setBounds(140, 120, 130, 25); //

     ctDengLu.add(userName);

     userName.setOpaque(false);// ÎÄ???òÍ?Ã?

     password.setBounds(140, 150, 130, 25); //

     ctDengLu.add(password);

     password.setOpaque(false);// ÎÄ???òÍ?Ã?

     // µÇÂ?

     deng.setBounds(100, 200, 70, 30);

     ctDengLu.add(deng);

     //deng.setEnabled(false);//???ÉÓÃ

     deng.setContentAreaFilled(false);// ??Å?Í?Ã?

     deng.addActionListener(new ActionListener() {

     public void actionPerformed(ActionEvent e) {

     dengluo(e);

     }

     });

     // ×??á

     zhuce.setBounds(200, 200, 70, 30);

     ctDengLu.add(zhuce);

     zhuce.setContentAreaFilled(false);// ??Å?Í?Ã?

     zhuce.addActionListener(new ActionListener() {

     public void actionPerformed(ActionEvent a) {

     zhuce(a);

     }

     });

     jf.setVisible(true); // ÏÔÊ???Ìå

     jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     }

     public void zhuce(ActionEvent arg0) {

     zhuc();

     zhuce.addActionListener(new ActionListener() {

     public void actionPerformed(ActionEvent e) {

     zhuceo(e);

     }

     });

     fanhui.addActionListener(new ActionListener() {

     public void actionPerformed(ActionEvent e) {

     jb.dispose();

     kuang();

     }

     });

     }

     public void zhuc(){

     jf.dispose();

     jb = new JFrame();

     jb.setContentPane(new MyPanel()); // ????Í?

     zhuce = new JButton("È???");

     chongzhi = new JButton("ÖØÖÃ");

     fanhui = new JButton("?µ?Ø");

     namelabel = new JLabel("ÓÃ??Ãû?º");

     mimalabel = new JLabel("ÃÜ Âë?º");

     nilabel = new JLabel("êÇ ?Æ?º");

     minglabel = new JLabel("ÐÕ Ãû?º");

     nianlabel = new JLabel("Äê Áä?º");

     xinglabel = new JLabel("ÐÔ ?ð?º");

     dianlabel = new JLabel("µç ???º");

     zhuanlabel = new JLabel("×? Òµ?º");

     zhuzhilabel = new JLabel("×? Ö??º");

     qitalabel = new JLabel("Æä Ëû?º");

     //qitaText = new TextArea();

     nameField = new JTextField();

     mimaField = new JTextField();

     niField = new JTextField();

     mingField = new JTextField();

     nianField = new JTextField();

     xingField = new JTextField();

     dianField = new JTextField();

     zhuanField = new JTextField();

     zhuzhiField = new JTextField();

     qita = new JTextArea(18, 26);

     jb.setSize(400, 450);

     jb.setLocation(400, 100);

     jb.setVisible(true); // ÏÔÊ???Ìå

     jb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     // jb.setUndecorated(true); //È??ýÍâ?ò

     Container bj = jb.getContentPane();

     bj.setLayout(null);

     namelabel.setBounds(20, 50, 60, 25);

     bj.add(namelabel);

     nameField.setBounds(80, 50, 100, 25);

     bj.add(nameField);

     nameField.setOpaque(false);// ÎÄ???òÍ?Ã?

     mimalabel.setBounds(200, 50, 60, 25);

     bj.add(mimalabel);

     mimaField.setBounds(260, 50, 100, 25);

     bj.add(mimaField);

     mimaField.setOpaque(false);// ÎÄ???òÍ?Ã?

     nilabel.setBounds(20, 90, 60, 25);

     bj.add(nilabel);

     niField.setBounds(80, 90, 100, 25);

     bj.add(niField);

     niField.setOpaque(false);// ÎÄ???òÍ?Ã?

     minglabel.setBounds(200, 90, 60, 25);

     bj.add(minglabel);

     mingField.setBounds(260, 90, 100, 25);

     bj.add(mingField);

     mingField.setOpaque(false);// ÎÄ???òÍ?Ã?

     nianlabel.setBounds(20, 130, 60, 25);

     bj.add(nianlabel);

     nianField.setBounds(80, 130, 100, 25);

     bj.add(nianField);

     nianField.setOpaque(false);// ÎÄ???òÍ?Ã?

     xinglabel.setBounds(200, 130, 60, 25);

     bj.add(xinglabel);

     xingField.setBounds(260, 130, 100, 25);

     bj.add(xingField);

     xingField.setOpaque(false);// ÎÄ???òÍ?Ã?

     dianlabel.setBounds(20, 170, 60, 25);

     bj.add(dianlabel);

     dianField.setBounds(80, 170, 100, 25);

     bj.add(dianField);

     dianField.setOpaque(false);// ÎÄ???òÍ?Ã?

     zhuanlabel.setBounds(200, 170, 60, 25);

     bj.add(zhuanlabel);

     zhuanField.setBounds(260, 170, 100, 25);

     bj.add(zhuanField);

     zhuanField.setOpaque(false);// ÎÄ???òÍ?Ã?

     zhuzhilabel.setBounds(20, 210, 60, 25);

     bj.add(zhuzhilabel);

     zhuzhiField.setBounds(80, 210, 280, 25);

     bj.add(zhuzhiField);

     zhuzhiField.setOpaque(false);// ÎÄ???òÍ?Ã?

     qitalabel.setBounds(20, 250, 60, 25);

     bj.add(qitalabel);

     qita.grabFocus();

     qita.setLineWrap(true);// ÉèÖÃ×Ô????ÐÐ

     qita.setBounds(80, 250, 280, 80);

     qita.setOpaque(false);

     qita.setVisible(true);

     jb.add(qita);

     // qitaText.setBounds(80, 250, 280, 80);

     // bj.add(qitaText);

     zhuce.setBounds(50, 360, 60, 25);

     bj.add(zhuce);

     zhuce.setContentAreaFilled(false);// ??Å?Í?Ã?

     chongzhi.setBounds(160, 360, 60, 25);

     bj.add(chongzhi);

     chongzhi.setContentAreaFilled(false);// ??Å?Í?Ã?

     chongzhi.addActionListener(new ActionListener() {

     public void actionPerformed(ActionEvent e) {

     chongzhi(e);

     }

     });

     fanhui.setBounds(270, 360, 60, 25);

     bj.add(fanhui);

     fanhui.setContentAreaFilled(false);// ??Å?Í?Ã?

     }

     public void chongzhi(ActionEvent arg0) {

     nameField.setText("");

     mimaField.setText("");

     niField.setText("");

     mingField.setText("");

     nianField.setText("");

     xingField.setText("");

     dianField.setText("");

     zhuanField.setText("");

     zhuzhiField.setText("");

     qita.setText("");

     }

     private Connection cone(ActionEvent arg0) {

     Connection con = null; // Á??Ó?ÔÏó

     try {

     Class.forName("com.mysql.jdbc.Driver"); // 1?º?ÓÔØÇý??

     } catch (ClassNotFoundException e1) {

     System.out.println("Ã?ÓÐÕÒµ?Çý??");

     }

     try {

     con =

    DriverManager.getConnection("jdbc:mysql://localhost/renshi",

     "root", "123");

     } catch (SQLException e1) {

     e1.printStackTrace();

     System.out.println("Á??ÓÊý?Ý?â?íÎó");

     }

     return con;

     }

     public void dengluo(ActionEvent arg0) {

     Connection con = cone(null);

     Statement sql = null; // Statement?ÔÏó??SQLÓï?ä??

     ResultSet rs = null; // ?á?û???ÔÏó

     try {

     sql = con.createStatement();

     String sqlStr = "select * From qq";

     rs = sql.executeQuery(sqlStr); // ?ù?ÝËù??ÒåµÄStatementÖ?ÐÐÉú?ÉÏàÓ?µÄ?á?û?????æÔÚRSÖÐ

     String a = userName.getText();

     String b = password.getText();

     boolean o = false;

     if (a.equals("") && b.equals("")) {

     JOptionPane.showMessageDialog(null, "ÇëÊäÈëÓÃ??Ãû");

     } else {

     while (rs.next()) { // next() ?µ?ØÁÐ?íÖеÄÏÂÒ??öÔªËØ

     String ar = rs.getString(1);

     String br = rs.getString(2);

     if (a.equals(ar) && b.equals(br)) {

     jf.dispose();

     xin();

     o = true;

     break;

     }

     }

     if (o == false) {

     JOptionPane.showMessageDialog(null, "ÓÃ??Ãû?òÃÜÂë?íÎó");

     }

     }

     } catch (SQLException e) {

     e.printStackTrace();

     } finally {

     closeAll(con, sql, rs);

     }

     }

     public void xuan() {

     jie.getColumnModel().getColumn(0)

     .setCellRenderer(new TableCellRenderer() { // getColumn(0) ÖÐµÄ 0

     // ÊÇÈ???äÖÈ?Æ?ËùÔڵĵ?Ôª?ñ

     /*

     * (non-Javadoc)

     *

    ?Ë????ÓÃÓÚÏò????µ?ÓÃÕß?µ?ØÄ?Ò?µ?Ôª?ñµÄäÖÈ?Æ?????ÏÔÊ?Êý?ݵÄ×é??--?ò

    ?Ø?þ??

     * ?ÉÒÔΪJCheckBox JComboBox JTextArea µÈ

     *

     * @see javax.swing.table.TableCellRenderer#

     *

    getTableCellRendererComponent(javax.swing.JTable,

     * java.lang.Object, boolean, boolean, int, int)

     */

     @Override

     public Component

    getTableCellRendererComponent(

     JTable table, Object value,

     boolean isSelected, boolean hasFocus,

     int row, int column) {

     // ????ÓÃÓÚ?µ?صÄäÖÈ?×é?þ

     JRadioButton ck = new JRadioButton();

     // Ê??ßÓÐ??µãµÄÐÐ?ÔÓ?µÄ??Ñ??òÑ?ÖÐ

     ck.setSelected(isSelected);// ÉèÖÃ?ɵ?Ñ?

     // ÉèÖõ?Ñ?box.setSelected(hasFocus);

     // Ê???Ñ??òÔÚµ?Ôª?ñÄÚ?ÓÖÐÏÔÊ?

     ck.setHorizontalAlignment((int) 0.5f); // ÈÃ?êÇ?ÖеÄÎÄ×ÖÄÚÈÝÔÚ?êÇ?ÄÚ??ÕÕÖ???µÄ??Ê??ÔÆë

     return ck;

     }

     });

     }

     public void xin() {

     j = new JFrame();

     biaj = new JButton("?à??");

     shc = new JButton("É??ý");

     xig = new JButton("ÐÞ?Ä");

     fh = new JButton("?µ?Ø");

     j.setContentPane(new MyPanel()); // ????Í?

     Container co = j.getContentPane(); // getContentPane()???? ?µ?Ø

     co.setLayout(null); // ÉèÖÃ LayoutManager??

     columnName = new Vector();

     columnName.add("ÐòºÅ");

     columnName.add("Õ˺Å");

     columnName.add("ÃÜÂë");

     columnName.add("êÇ?Æ");

     columnName.add("ÐÕÃû");

     columnName.add("ÐÔ?ð");

     columnName.add("ÄêÁä");

     columnName.add("×?Òµ");

     columnName.add("µç??");

     columnName.add("µØÖ?");

     columnName.add("ÆäËû");

     rowData = new Vector();

     jie = new JTable(rowData, columnName);

     // ctDengLu = j.getContentPane();

     // ctDengLu.setLayout(null);

     xuan();

     JScrollPane jsp = new JScrollPane(jie);

     jsp.setSize(600, 400);

     jsp.setLocation(100, 50);

     co.add(jsp);

     biaj.setBounds(100, 25, 60, 25);

     //biaj.setEnabled(false);//???ÉÓÃ

     biaj.setContentAreaFilled(false);// ??Å?Í?Ã?

     shc.setBounds(160, 25, 60, 25);

     shc.setEnabled(false);//???ÉÓÃ

     shc.setContentAreaFilled(false);// ??Å?Í?Ã?

     xig.setBounds(220, 25, 60, 25);

     xig.setEnabled(false);//???ÉÓÃ

     xig.setContentAreaFilled(false);// ??Å?Í?Ã?

     fh.setBounds(280, 25, 60, 25);

     fh.setEnabled(false);//???ÉÓÃ

     fh.setContentAreaFilled(false);// ??Å?Í?Ã?

     j.add(biaj);

     j.add(shc);

     j.add(xig);

     j.add(fh);

     biaj.addActionListener(new ActionListener() {

     // @Override

     public void actionPerformed(ActionEvent e) {

     for (int rowindex : jie.getSelectedRows()) {

     shc.setEnabled(true);//?ÉÓÃ

     xig.setEnabled(true);//?ÉÓÃ

     fh.setEnabled(true);//?ÉÓÃ

     }

     }

     });

     fh.addActionListener(new ActionListener() {

     // @Override

     public void actionPerformed(ActionEvent e) {

     for (int rowindex : jie.getSelectedRows()) {

     shc.setEnabled(false);//???ÉÓÃ

     xig.setEnabled(false);//???ÉÓÃ

     fh.setEnabled(false);//???ÉÓÃ

     }

     }

     });

Report this document

For any questions or suggestions please email
cust-service@docsford.com