?? part_info.java
字號:
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.setForeground(Color.cyan);
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));
jLabel7.setForeground(Color.cyan);
jLabel7.setText("請輸入部門編號來查看或刪改");
jLabel7.setBounds(new Rectangle(237, 57, 162, 32));
jTextField8.setForeground(Color.cyan);
jTextField8.setBounds(new Rectangle(259, 96, 74, 33));
jButton6.setBounds(new Rectangle(352, 94, 110, 39));
jButton6.setForeground(Color.cyan);
jButton6.setText("清除所有信息");
jButton6.addActionListener(new part_Info_jButton6_actionAdapter(this));
this.getContentPane().setBackground(new Color(255, 106, 197));
jLabel2.setForeground(Color.cyan);
jLabel3.setForeground(Color.cyan);
jLabel4.setForeground(Color.cyan);
jLabel5.setForeground(Color.cyan);
jLabel6.setForeground(Color.cyan);
jButton1.setForeground(Color.cyan);
jButton2.setForeground(Color.cyan);
jButton3.setForeground(Color.cyan);
jButton4.setForeground(Color.cyan);
jTextField1.setForeground(Color.cyan);
jTextField2.setForeground(Color.cyan);
jTextField3.setForeground(Color.cyan);
jTextField4.setForeground(Color.cyan);
jTextField5.setForeground(Color.cyan);
jTextField6.setForeground(Color.cyan);
this.getContentPane().add(jLabel1);
jButton4.setBounds(new Rectangle(374, 151, 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(16, 225, 53, 33));
jLabel5.setText("郵編");
jLabel5.setBounds(new Rectangle(22, 183, 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(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(jTextField8);
this.getContentPane().add(jLabel7);
this.getContentPane().add(jButton6);
this.getContentPane().add(jButton4);
this.getContentPane().add(jLabel6);
this.getContentPane().add(jLabel5);
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();
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() +
"')";
} 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();
JOptionPane.showMessageDialog(null, "添加成功!", "部門信息添加對話框",
JOptionPane.INFORMATION_MESSAGE);
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 + -