⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bumenshezhi.java~18~

📁 中小学校园的教师
💻 JAVA~18~
字号:
package untitled2;import javax.swing.*;import java.awt.*;import java.awt.event.*;import com.borland.jbcl.layout.*;import java.awt.event.*;import com.borland.jbcl.layout.*;import java.sql.*;import java.sql.Statement;import java.sql.SQLException;import java.sql.Statement;import java.sql.Connection;import java.sql.ResultSet;import com.borland.dbswing.*;import java.awt.event.*;import com.borland.dx.sql.dataset.*;import javax.swing.border.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2006</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class BuMenSheZhi extends JFrame {  XYLayout xYLayout1 = new XYLayout();  JLabel jLabel1 = new JLabel();  JLabel jLabel3 = new JLabel();  JLabel jLabel4 = new JLabel();  JLabel jLabel5 = new JLabel();  JLabel jLabel6 = new JLabel();  JButton jButton1 = new JButton();  JButton jButton2 = new JButton();  JButton jButton3 = new JButton();  JTextField jTextField2 = new JTextField();  JTextField jTextField4 = new JTextField();  JTextField jTextField5 = new JTextField();  JTextField jTextField1 = new JTextField();  JButton jButton4 = new JButton();  JButton jButton5 = new JButton();  Database database1 = new Database();  QueryDataSet queryDataSet1 = new QueryDataSet();  TableScrollPane tableScrollPane2 = new TableScrollPane();  JButton jButton6 = new JButton();  JdbTable jdbTable1 = new JdbTable();  Border border1;  JLabel jLabel2 = new JLabel();  public BuMenSheZhi() {    try {      jbInit();    }    catch (Exception ex) {      ex.printStackTrace();    }  }  void jbInit() throws Exception {    border1 = new EtchedBorder(EtchedBorder.RAISED,Color.white,SystemColor.desktop);    this.getContentPane().setBackground(SystemColor.text);    this.setEnabled(true);    this.setState(Frame.NORMAL);    this.setTitle("欢迎您进入部门设置界面");    this.getContentPane().setLayout(xYLayout1);    this.setSize(new Dimension(800, 600));    jLabel1.setFont(new java.awt.Font("Dialog", 0, 14));    jLabel1.setForeground(new Color(13, 98, 144));    jLabel1.setText("请输入以下信息:");    jLabel3.setFont(new java.awt.Font("幼圆", 0, 13));    jLabel3.setForeground(new Color(13, 98, 144));    jLabel3.setText("部门电话");    jLabel4.setFont(new java.awt.Font("幼圆", 0, 13));    jLabel4.setForeground(new Color(13, 98, 144));    jLabel4.setText("部门名称");    jLabel5.setFont(new java.awt.Font("幼圆", 0, 13));    jLabel5.setForeground(new Color(13, 98, 144));    jLabel5.setText("部门办公室");    jLabel6.setFont(new java.awt.Font("幼圆", 0, 13));    jLabel6.setForeground(new Color(13, 98, 144));    jLabel6.setText("部门主任");    jButton1.setBackground(new Color(131, 177, 197));    jButton1.setFont(new java.awt.Font("Dialog", 0, 13));    jButton1.setBorder(border1);    jButton1.setText("清空");    jButton1.addActionListener(new BuMenSheZhi_jButton1_actionAdapter(this));    jButton2.setBackground(new Color(131, 177, 197));    jButton2.setFont(new java.awt.Font("Dialog", 0, 13));    jButton2.setBorder(border1);    jButton2.setVerifyInputWhenFocusTarget(true);    jButton2.setText("退出");    jButton2.addActionListener(new BuMenSheZhi_jButton2_actionAdapter(this));    jButton3.setBackground(new Color(131, 177, 197));    jButton3.setFont(new java.awt.Font("Dialog", 0, 13));    jButton3.setBorder(border1);    jButton3.setText("更改");    jButton3.addActionListener(new BuMenSheZhi_jButton3_actionAdapter(this));    jTextField2.setBorder(border1);    jTextField2.setText("");    jTextField5.setBorder(border1);    jTextField5.setText("");    jButton4.addActionListener(new BuMenSheZhi_jButton4_actionAdapter(this));    jButton4.setText("添加");    jButton4.setBackground(new Color(131, 177, 197));    jButton4.setFont(new java.awt.Font("Dialog", 0, 13));    jButton4.setBorder(border1);    jButton5.addActionListener(new BuMenSheZhi_jButton5_actionAdapter(this));    jButton5.setText("删除");    jButton5.setBackground(new Color(131, 177, 197));    jButton5.setFont(new java.awt.Font("Dialog", 0, 13));    jButton5.setBorder(border1);    database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor(        "jdbc:odbc:Digital_campus", "dbw", "123456", false,        "sun.jdbc.odbc.JdbcOdbcDriver"));    queryDataSet1.setReadOnly(false);    queryDataSet1.setResolvable(true);    queryDataSet1.setAccumulateResults(false);    queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(        database1,        "SELECT department.department_id as \"部门编号\",department.department_name " +        "as \"部门名称\",department.department_master as \"部门主管\",department.department_telephone " +        "as \"部门电话\",department.department_office as \"部门办公室\" FROM Digital_Campus.dbo.department", null, true,        Load.ALL));    tableScrollPane2.setFont(new java.awt.Font("Dialog", 0, 13));    tableScrollPane2.setAutoscrolls(true);    tableScrollPane2.setMinimumSize(new Dimension(800, 600));    xYLayout1.setWidth(816);    xYLayout1.setHeight(508);    jButton6.setBackground(new Color(133, 177, 197));    jButton6.setFont(new java.awt.Font("Dialog", 0, 13));    jButton6.setBorder(border1);    jButton6.setDebugGraphicsOptions(0);    jButton6.setActionCommand("刷新所有记录");    jButton6.setContentAreaFilled(true);    jButton6.setHorizontalAlignment(SwingConstants.CENTER);    jButton6.setText("刷新所有记录");    jButton6.addActionListener(new BuMenSheZhi_jButton6_actionAdapter(this));    jdbTable1.setFont(new java.awt.Font("Dialog", 0, 13));    jdbTable1.setDataSet(queryDataSet1);    jTextField1.setBorder(border1);    jTextField4.setBorder(border1);    jLabel2.setIcon(new ImageIcon(new java.net.URL("file:///D:/UI6.0/untitled2/pictrue/pen.JPG")));    jLabel2.setText("jLabel2");    this.getContentPane().add(jLabel5, new XYConstraints(402, 80, 67, -1));    this.getContentPane().add(jLabel3, new XYConstraints(401, 45, 76, -1));    this.getContentPane().add(jTextField4,   new XYConstraints(505, 41, 148, -1));    this.getContentPane().add(jTextField5,     new XYConstraints(504, 77, 148, -1));    this.getContentPane().add(jLabel1,  new XYConstraints(26, 9, -1, -1));    this.getContentPane().add(jButton2,  new XYConstraints(586, 142, 61, 26));    this.getContentPane().add(jButton3,   new XYConstraints(335, 142, 63, 26));    this.getContentPane().add(jButton4,  new XYConstraints(204, 142, 64, -1));    this.getContentPane().add(jButton5,   new XYConstraints(464, 142, 61, 26));    this.getContentPane().add(tableScrollPane2,  new XYConstraints(30, 194, 540, 247));    this.getContentPane().add(jLabel6, new XYConstraints(26, 85, -1, -1));    this.getContentPane().add(jLabel4, new XYConstraints(25, 38, 53, 32));    this.getContentPane().add(jTextField1, new XYConstraints(111, 44, 174, -1));    this.getContentPane().add(jTextField2,  new XYConstraints(114, 84, 175, -1));    this.getContentPane().add(jButton1, new XYConstraints(85, 142, 62, -1));    this.getContentPane().add(jButton6,   new XYConstraints(624, 412, 147, -1));    this.getContentPane().add(jLabel2,        new XYConstraints(601, 221, 203, 171));    tableScrollPane2.getViewport().add(jdbTable1, null);  }  void jButton2_actionPerformed(ActionEvent e) {    this.dispose();  }  void jButton1_actionPerformed(ActionEvent e) {    jTextField1.setEditable(true);      jTextField2.setEditable(true);      jTextField4.setEditable(true);      jTextField5.setEditable(true);    jTextField2.setText("");    jTextField1.setText("");    jTextField4.setText("");    jTextField5.setText("");  }  void jButton3_actionPerformed(ActionEvent e) {    String sql = "update department set department_master=?,department_telephone=?,department_office=? where department_name=?";    Connection con = null;    try {      con = DBConnection.getConnection();      PreparedStatement ps = con.prepareStatement(sql);      ps.setString(1, jTextField2.getText());      ps.setString(2, jTextField4.getText());      ps.setString(3, jTextField5.getText());      ps.setString(4, jTextField1.getText());      ps.executeUpdate();      jTextField1.setEditable(false);      jTextField2.setEditable(false);      jTextField4.setEditable(false);      jTextField5.setEditable(false);      JOptionPane.showMessageDialog(null, "更改成功!");      DbUtil.close(ps);    }    catch (Exception ex) {      ex.printStackTrace();    }    finally {      DbUtil.close(con);    }  }  void jButton4_actionPerformed(ActionEvent e) {    String sql1 ="select * from department where department_name=?";    String sql = "insert department (department_name,department_master,department_telephone,department_office) values (?,?,?,?) ";    Connection con = null;    try {      con = DBConnection.getConnection();      PreparedStatement ps= con.prepareStatement(sql1);       ps.setString(1, jTextField1.getText());       ResultSet rs1= ps.executeQuery();      boolean more= rs1.next();    if(more)    {      JOptionPane.showMessageDialog(null, "该部门已存在!");      DbUtil.close(ps);      DbUtil.close(rs1);      DbUtil.close(con);    }      else      {          con = DBConnection.getConnection();      ps = con.prepareStatement(sql);        ps.setString(1, jTextField1.getText());        ps.setString(2, jTextField2.getText());        ps.setString(3, jTextField4.getText());        ps.setString(4, jTextField5.getText());        ps.executeUpdate();        jTextField1.setEditable(false);        jTextField2.setEditable(false);        jTextField4.setEditable(false);        jTextField5.setEditable(false);        JOptionPane.showMessageDialog(null, "添加成功!");        DbUtil.close(ps);      }    }    catch (Exception ex) {      ex.printStackTrace();    }    finally {      DbUtil.close(con);    }  }  void jButton5_actionPerformed(ActionEvent e) {    String sql = "delete department where department_name=? ";    Connection con = null;    try {      con = DBConnection.getConnection();      PreparedStatement ps = con.prepareStatement(sql);      ps.setString(1, jTextField1.getText());      ps.executeUpdate();      jTextField1.setEditable(false);      jTextField2.setEditable(false);      jTextField4.setEditable(false);      jTextField5.setEditable(false);      DbUtil.close(ps);      JOptionPane.showMessageDialog(null, "成功删除!");    }    catch (SQLException exc) {      JOptionPane.showMessageDialog(null, "该部门存在相关的记录,不能删除");    }    catch (Exception ex) {      ex.printStackTrace();    }    finally {      DbUtil.close(con);    }  }  void jButton6_actionPerformed(ActionEvent e) {    queryDataSet1.refresh();  }  class BuMenSheZhi_jButton2_actionAdapter      implements java.awt.event.ActionListener {    BuMenSheZhi adaptee;    BuMenSheZhi_jButton2_actionAdapter(BuMenSheZhi adaptee) {      this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {      adaptee.jButton2_actionPerformed(e);    }  }  class BuMenSheZhi_jButton1_actionAdapter      implements java.awt.event.ActionListener {    BuMenSheZhi adaptee;    BuMenSheZhi_jButton1_actionAdapter(BuMenSheZhi adaptee) {      this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {      adaptee.jButton1_actionPerformed(e);    }  }  class BuMenSheZhi_jButton3_actionAdapter      implements java.awt.event.ActionListener {    BuMenSheZhi adaptee;    BuMenSheZhi_jButton3_actionAdapter(BuMenSheZhi adaptee) {      this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {      adaptee.jButton3_actionPerformed(e);    }  }  class BuMenSheZhi_jButton4_actionAdapter      implements java.awt.event.ActionListener {    BuMenSheZhi adaptee;    BuMenSheZhi_jButton4_actionAdapter(BuMenSheZhi adaptee) {      this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {      adaptee.jButton4_actionPerformed(e);    }  }  class BuMenSheZhi_jButton5_actionAdapter      implements java.awt.event.ActionListener {    BuMenSheZhi adaptee;    BuMenSheZhi_jButton5_actionAdapter(BuMenSheZhi adaptee) {      this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {      adaptee.jButton5_actionPerformed(e);    }  }  class BuMenSheZhi_jButton6_actionAdapter      implements java.awt.event.ActionListener {    BuMenSheZhi adaptee;    BuMenSheZhi_jButton6_actionAdapter(BuMenSheZhi adaptee) {      this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {      adaptee.jButton6_actionPerformed(e);    }  }}class BuMenSheZhi_jButton4_actionAdapter implements java.awt.event.ActionListener {  BuMenSheZhi adaptee;  BuMenSheZhi_jButton4_actionAdapter(BuMenSheZhi adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton4_actionPerformed(e);  }}class BuMenSheZhi_jButton5_actionAdapter implements java.awt.event.ActionListener {  BuMenSheZhi adaptee;  BuMenSheZhi_jButton5_actionAdapter(BuMenSheZhi adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton5_actionPerformed(e);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -