📄 part_info.java~27~
字号:
package scince;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class part_Info extends JFrame {
public part_Info() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
jLabel1.setText("部门编号*");
jLabel1.setBounds(new Rectangle(17, 8, 85, 24));
jButton1.addActionListener(new part_Info_jButton1_actionAdapter(this));
jButton2.addActionListener(new part_Info_jButton2_actionAdapter(this));
jButton3.addActionListener(new part_Info_jButton3_actionAdapter(this));
jButton4.addActionListener(new part_Info_jButton4_actionAdapter(this));
jButton5.setBounds(new Rectangle(373, 151, 81, 37));
jButton5.setText("修改");
jLabel7.setText("请输入部门编号来查看或删改");
jLabel7.setBounds(new Rectangle(237, 57, 162, 32));
jTextField8.setBounds(new Rectangle(259, 96, 74, 33));
jButton6.setBounds(new Rectangle(352, 94, 110, 39));
jButton6.setText("清除所有信息");
jButton6.addActionListener(new part_Info_jButton6_actionAdapter(this));
this.getContentPane().add(jLabel1);
jButton4.setBounds(new Rectangle(374, 225, 76, 37));
jButton4.setText("退出");
jButton3.setBounds(new Rectangle(256, 151, 80, 35));
jButton3.setText("添加");
jButton2.setBounds(new Rectangle(372, 21, 75, 31));
jButton2.setText("删除");
jButton1.setBounds(new Rectangle(260, 19, 74, 33));
jButton1.setText("查看");
jTextField6.setBounds(new Rectangle(108, 226, 90, 28));
jTextField5.setBounds(new Rectangle(110, 185, 87, 29));
jTextField4.setBounds(new Rectangle(109, 138, 87, 34));
jTextField3.setBounds(new Rectangle(109, 92, 85, 34));
jTextField2.setBounds(new Rectangle(109, 50, 85, 31));
jTextField1.setBounds(new Rectangle(110, 7, 84, 29));
jLabel6.setText("联系电话");
jLabel6.setBounds(new Rectangle(22, 211, 53, 33));
jLabel5.setText("邮编");
jLabel5.setBounds(new Rectangle(21, 171, 54, 36));
jLabel4.setText("地址");
jLabel4.setBounds(new Rectangle(21, 134, 56, 32));
jLabel3.setText("负责人");
jLabel3.setBounds(new Rectangle(19, 88, 57, 27));
this.getContentPane().add(jLabel3);
this.getContentPane().add(jLabel4);
this.getContentPane().add(jLabel5);
this.getContentPane().add(jLabel6);
this.getContentPane().add(jTextField1);
this.getContentPane().add(jTextField2);
this.getContentPane().add(jTextField3);
this.getContentPane().add(jTextField4);
this.getContentPane().add(jTextField5);
this.getContentPane().add(jTextField6);
this.getContentPane().add(jButton1);
this.getContentPane().add(jTextField7);
this.getContentPane().add(jLabel2);
this.getContentPane().add(jButton2);
this.getContentPane().add(jButton3);
this.getContentPane().add(jButton5);
this.getContentPane().add(jTextField8);
this.getContentPane().add(jLabel7);
this.getContentPane().add(jButton6);
this.getContentPane().add(jButton4);
jLabel2.setText("部门名称");
jLabel2.setBounds(new Rectangle(13, 41, 56, 32));
}
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JTextField jTextField4 = new JTextField();
JTextField jTextField5 = new JTextField();
JTextField jTextField6 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JTextField jTextField7 = new JTextField();
JButton jButton5 = new JButton();
JLabel jLabel7 = new JLabel();
JTextField jTextField8 = new JTextField();
JButton jButton6 = new JButton();
public void jButton1_actionPerformed(ActionEvent e) {
Connection con;
Statement sql;
ResultSet rs;
String queryString;
if (!jTextField8.getText().equals("")) {
queryString = "select * from 部门信息 where 部门编号=" +
Integer.parseInt(jTextField8.getText());
} else {
queryString = "";
JOptionPane.showMessageDialog(null, "请输入部门编号查看,不能为空,请确认后认真填写",
"部门信息查询对话框",
JOptionPane.INFORMATION_MESSAGE);
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (java.lang.ClassNotFoundException ee) {
System.err.print("class not find!");
System.err.println(ee.getMessage());
}
try {
con = DriverManager.getConnection("jdbc:odbc:scince", "", "");
sql = con.createStatement();
rs = sql.executeQuery(queryString);
if (rs.next()) {
jTextField1.setText(Integer.toString(rs.getInt(1)));
jTextField2.setText(rs.getString(2));
jTextField3.setText(rs.getString(3));
jTextField4.setText(rs.getString(4));
jTextField5.setText(rs.getString(5));
jTextField6.setText(rs.getString(6));
} else {
JOptionPane.showMessageDialog(null, "没有找到您要求的部门信息,请重新填写!",
"部门信息查询对话框",
JOptionPane.INFORMATION_MESSAGE);
}
con.close();
} catch (SQLException ex) {}
}
public void jButton2_actionPerformed(ActionEvent e) {
Connection con;
Statement sql;
ResultSet rs;
String queryString; // 删除语句
String queryString1; //查找确认语句
if (!jTextField8.getText().equals("")) {
queryString = "DELETE from 部门信息 where 部门编号=" +
Integer.parseInt(jTextField8.getText());
queryString1 = "select * from 部门信息 where 部门编号=" +
Integer.parseInt(jTextField8.getText());
} else {
queryString = "";
queryString1 = "";
JOptionPane.showMessageDialog(null, "请输入内容,请确认后认真填写", "部门信息删除对话框",
JOptionPane.INFORMATION_MESSAGE);
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (java.lang.ClassNotFoundException ee) {
System.err.print("class not find!");
System.err.println(ee.getMessage());
}
try {
con = DriverManager.getConnection("jdbc:odbc:scince", "", "");
sql = con.createStatement();
rs = sql.executeQuery(queryString1);
if (rs.next()) {
JOptionPane.showMessageDialog(null, "删除成功!", "部门信息删除对话框",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "没有找到您要删除的部门!", "部门信息删除对话框",
JOptionPane.INFORMATION_MESSAGE);
}
sql.executeUpdate(queryString);
con.close();
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField8.setText("");
} catch (SQLException ex) {}
}
public void jButton3_actionPerformed(ActionEvent e) {
Connection con;
Statement sql;
String queryString;
if (!jTextField1.getText().equals("")) {
queryString = "INSERT INTO 部门信息 VALUES('" +
Integer.parseInt(jTextField1.getText()) + "','" +
jTextField2.getText() + "','" + jTextField3.getText() +
"','" + jTextField4.getText() + "','" +
jTextField5.getText() + "','" + jTextField6.getText() +
"')";
JOptionPane.showMessageDialog(null, "添加成功!", "部门信息添加对话框",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "部门编号为必填信息不能为空,请添加完整后在添加!",
"部门信息添加对话框",
JOptionPane.INFORMATION_MESSAGE);
queryString = "";
}
;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (java.lang.ClassNotFoundException ee) {
System.err.print("class not find!");
System.err.println(ee.getMessage());
}
try {
con = DriverManager.getConnection("jdbc:odbc:scince", "", "");
con.setAutoCommit(false);
sql = con.createStatement();
sql.executeUpdate(queryString);
con.commit();
con.close();
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
} catch (SQLException ex) {}
}
public void jButton4_actionPerformed(ActionEvent e) {
this.dispose();
}
public void jButton6_actionPerformed(ActionEvent e) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField8.setText("");
}
class part_Info_jButton4_actionAdapter implements ActionListener {
private part_Info adaptee;
part_Info_jButton4_actionAdapter(part_Info adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
class part_Info_jButton3_actionAdapter implements ActionListener {
private part_Info adaptee;
part_Info_jButton3_actionAdapter(part_Info adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class part_Info_jButton2_actionAdapter implements ActionListener {
private part_Info adaptee;
part_Info_jButton2_actionAdapter(part_Info adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class part_Info_jButton1_actionAdapter implements ActionListener {
private part_Info adaptee;
part_Info_jButton1_actionAdapter(part_Info adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
}
class part_Info_jButton6_actionAdapter implements ActionListener {
private part_Info adaptee;
part_Info_jButton6_actionAdapter(part_Info adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton6_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -