📄 frame6.java~28~
字号:
package liulei;
import java.lang.*;
import java.lang.Object.*;
import java.sql.*;
import java.util.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame6 extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JToggleButton jToggleButton1 = new JToggleButton();
JTextField jTextField1 = new JTextField();
JToggleButton jToggleButton2 = new JToggleButton();
JToggleButton jToggleButton3 = new JToggleButton();
JTextArea jTextArea1 = new JTextArea();
JTextArea jTextArea2 = new JTextArea();
JTextArea jTextArea3 = new JTextArea();
JTextArea jTextArea4 = new JTextArea();
JTextArea jTextArea5 = new JTextArea();
JTextArea jTextArea6 = new JTextArea();
JTextArea jTextArea7 = new JTextArea();
JTextArea jTextArea8 = new JTextArea();
JToggleButton jToggleButton4 = new JToggleButton();
//Construct the frame
public Frame6() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
jLabel1.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel1.setText("汽车信息");
jLabel1.setBounds(new Rectangle(159, 6, 119, 32));
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
this.addHierarchyBoundsListener(new Frame6_this_hierarchyBoundsAdapter(this));
jLabel2.setText("汽车编号");
jLabel2.setBounds(new Rectangle(6, 53, 50, 22));
jLabel3.setText("汽车编号");
jLabel3.setBounds(new Rectangle(7, 88, 45, 16));
jLabel4.setText("汽车车型");
jLabel4.setBounds(new Rectangle(5, 121, 46, 16));
jLabel5.setText("汽车排量");
jLabel5.setBounds(new Rectangle(5, 158, 49, 16));
jLabel6.setText("进货价格");
jLabel6.setBounds(new Rectangle(198, 55, 45, 16));
jLabel7.setText("销售价格");
jLabel7.setBounds(new Rectangle(196, 88, 49, 16));
jLabel8.setText("性能");
jLabel8.setBounds(new Rectangle(202, 119, 50, 16));
jLabel9.setText("库存");
jLabel9.setBounds(new Rectangle(203, 156, 34, 16));
jToggleButton1.setText("填加");
jToggleButton1.setBounds(new Rectangle(14, 236, 86, 25));
jToggleButton1.addActionListener(new Frame6_jToggleButton1_actionAdapter(this));
jToggleButton1.addActionListener(new Frame6_jToggleButton1_actionAdapter(this));
jTextField1.setText("");
jTextField1.setBounds(new Rectangle(127, 239, 67, 20));
jToggleButton2.setText("查看");
jToggleButton2.setBounds(new Rectangle(207, 237, 81, 25));
jToggleButton2.addFocusListener(new Frame6_jToggleButton2_focusAdapter(this));
jToggleButton3.setText("删除");
jToggleButton3.setBounds(new Rectangle(296, 237, 80, 25));
jToggleButton3.addAncestorListener(new Frame6_jToggleButton3_ancestorAdapter(this));
jToggleButton3.addComponentListener(new
Frame6_jToggleButton3_componentAdapter(this));
jTextArea1.setText("");
jTextArea1.setBounds(new Rectangle(63, 57, 100, 17));
jTextArea2.setText("");
jTextArea2.setBounds(new Rectangle(62, 89, 103, 21));
jTextArea3.setText("");
jTextArea3.setBounds(new Rectangle(61, 121, 105, 19));
jTextArea4.setText("");
jTextArea4.setBounds(new Rectangle(62, 151, 102, 24));
jTextArea5.setText("");
jTextArea5.setBounds(new Rectangle(250, 55, 125, 19));
jTextArea6.setText("");
jTextArea6.setBounds(new Rectangle(253, 90, 121, 18));
jTextArea7.setText("");
jTextArea7.setBounds(new Rectangle(251, 118, 123, 18));
jTextArea8.setText("");
jTextArea8.setBounds(new Rectangle(248, 155, 127, 18));
jToggleButton4.setText("jToggleButton4");
jToggleButton4.setBounds(new Rectangle(195, 276, 103, 25));
jToggleButton4.addAncestorListener(new Frame6_jToggleButton4_ancestorAdapter(this));
contentPane.add(jLabel1, null);
contentPane.add(jLabel2, null);
contentPane.add(jLabel4, null);
contentPane.add(jLabel6, null);
contentPane.add(jLabel5, null);
contentPane.add(jLabel3, null);
contentPane.add(jLabel9, null);
contentPane.add(jToggleButton2, null);
contentPane.add(jTextField1, null);
contentPane.add(jToggleButton1, null);
contentPane.add(jTextArea1, null);
contentPane.add(jTextArea2, null);
contentPane.add(jTextArea3, null);
contentPane.add(jLabel8, null);
contentPane.add(jLabel7, null);
contentPane.add(jTextArea4, null);
contentPane.add(jTextArea5, null);
contentPane.add(jTextArea6, null);
contentPane.add(jTextArea7, null);
contentPane.add(jTextArea8, null);
contentPane.add(jToggleButton3, null);
contentPane.add(jToggleButton4, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
// System.exit(0);
}
}
void jToggleButton1_actionPerformed(ActionEvent e) {
Connection connection = null; // 声明Connection接口对象connection
Statement statement = null; // 定义查询数据库的Statement对象
String ygxinxi[] = {
"qichebh", "qichepz", "qichecx", "qichepl", "qichejhjg", "qichexsjg",
"qichexn", "qichekc"}; // 二维表列名
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // 实例化JDBC-ODBC桥的驱动
connection = DriverManager.getConnection("jdbc:odbc:liulei"); // 连接数据库
// 创建Statement接口对象
statement = connection.createStatement();
String sql1 = "insert into qichexinxi values ('" + jTextArea1.getText() +
"','" + jTextArea2.getText() + "','" + jTextArea3.getText() + "','" +
jTextArea4.getText() + "','" + jTextArea5.getText() + "','" +
jTextArea6.getText() + "','"
+ jTextArea7.getText() + "','" + jTextArea8.getText() + "')";
if (jTextArea1.getText().length() == 0) {
// jTextPane1.setText("不能修改,请先输入学号!");
// 清空信息框
jTextArea1.setText("");
jTextArea2.setText("");
jTextArea3.setText("");
jTextArea4.setText("");
jTextArea5.setText("");
jTextArea6.setText("");
jTextArea7.setText("");
jTextArea8.setText("");
// jTextArea9.setText("");
// jTextArea10.setText("");
//jTextArea11.setText("");
}
else {
statement.executeUpdate(sql1); // stu_info表中添加记录
// jTextPane1.setText("记录添加成功!");
// 清空信息框
jTextArea1.setText("");
jTextArea2.setText("");
jTextArea3.setText("");
jTextArea4.setText("");
jTextArea5.setText("");
jTextArea6.setText("");
jTextArea7.setText("");
jTextArea8.setText("");
// jTextArea9.setText("");
// jTextArea10.setText("");
// jTextArea11.setText("");
}
}
catch (SQLException ex) { // 捕捉异常
//jTextPane1.setText(ex.getMessage());
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null) {
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
try {
if (statement != null) {
statement.close(); // 关闭Statement接口实例
}
if (connection != null) {
connection.close(); // 关闭Connection接口实例
}
}
catch (SQLException ex) {
System.out.println("\nERROR:----- SQLException -----\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
class Frame6_jToggleButton1_actionAdapter
implements java.awt.event.ActionListener {
Frame6 adaptee;
Frame6_jToggleButton1_actionAdapter(Frame6 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jToggleButton1_actionPerformed(e);
}
}
void this_ancestorMoved(HierarchyEvent e) {
}
//void jToggleButton3_componentShown(ComponentEvent e) {
//}
//}
void jToggleButton2_focusGained(FocusEvent e) {
Connection connection = null; // 声明Connection接口对象connection
Statement statement = null; // 定义查询数据库的Statement对象
ResultSet rSet = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // 实例化JDBC-ODBC桥的驱动
connection = DriverManager.getConnection("jdbc:odbc:liulei");
// // String data_driver="sun.jdbc.odbc.JdbcOdbcDriver";
// Class.forName(data_driver);
// String connectionStr="jdbc:odbc:liulei";
// Connection con=DriverManager.getConnection(connectionStr, "", ""); //没有配置用户名和密码就用空代替
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(
"select * from qichexinxi where qichebh='" +
Integer.parseInt(jTextField1.getText()) + "'");
jTextField1.setText("");
// ResultSet rs=stmt.executeQuery("select * From cost where an and jCostMonth="+Integer.parseInt(textMonth.getText())+"");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -