📄 updata1.java
字号:
package Resource_Selection;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import com.borland.dx.sql.dataset.*;
public class updata1 extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
//Construct the frame
public updata1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
jLabel1.setText(Resource_Selection.user.ip_updata.ip);
jLabel1.setBounds(new Rectangle(23, 21, 157, 29));
contentPane.setLayout(null);
this.setSize(new Dimension(306, 351));
this.setTitle("信息修改");
jTextField1.setText("");
jTextField1.setBounds(new Rectangle(83, 50, 133, 31));
jTextField2.setText("");
jTextField2.setBounds(new Rectangle(83, 84, 133, 31));
jLabel2.setText("名称");
jLabel2.setBounds(new Rectangle(9, 50, 66, 31));
jLabel3.setText("机群");
jLabel3.setBounds(new Rectangle(8, 84, 64, 31));
jLabel4.setText("是否开放");
jLabel4.setBounds(new Rectangle(7, 118, 61, 28));
jComboBox1.setBounds(new Rectangle(83, 120, 133, 28));
jComboBox1.addItem("yes");
jComboBox1.addItem("no");
jButton1.setBounds(new Rectangle(6, 169, 85, 31));
jButton1.setText("确定");
jButton1.addActionListener(new updata1_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(118, 169, 101, 31));
jButton2.setText("关闭");
jButton2.addActionListener(new updata1_jButton2_actionAdapter(this));
contentPane.add(jLabel1, null);
contentPane.add(jTextField1, null);
contentPane.add(jTextField2, null);
contentPane.add(jLabel2, null);
contentPane.add(jLabel3, null);
contentPane.add(jLabel4, null);
contentPane.add(jComboBox1, null);
contentPane.add(jButton1, null);
contentPane.add(jButton2, null);
String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
String connectionURL = "jdbc:odbc:computer"; //driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\WINDOWS\\Desktop\\desktop\\毕业设计\\Grid\\computer.mdb";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String adm = null;
try {
Class.forName(driverName).newInstance();
con = DriverManager.getConnection(connectionURL);
stmt = con.createStatement();
rs=stmt.executeQuery("select * from computer where 地址 ='" +
Resource_Selection.user.ip_updata.ip + "'");
if (rs.next()) {
jTextField1.setText(rs.getString("名称"));
jTextField2.setText(rs.getString("机群"));
}
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
try {
rs.close();
stmt.close();
con.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
this.dispose();
}
}
void jButton2_actionPerformed(ActionEvent e) {
this.dispose();
}
private void query(String command) {
String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
String connectionURL = "jdbc:odbc:computer";//driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\WINDOWS\\Desktop\\desktop\\毕业设计\\Grid\\computer.mdb";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String adm = null;
try {
Class.forName(driverName).newInstance();
con = DriverManager.getConnection(connectionURL);
stmt = con.createStatement();
rs=stmt.executeQuery(command);
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally {
try {
rs.close();
stmt.close();
con.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
void jButton1_actionPerformed(ActionEvent e) {
String table,table_1,table_2,sql;
int table_3;
String system[]=new String[2];
system[0]="y";
system[1]="n";
table=Resource_Selection.user.ip_updata.ip;
table_3=jComboBox1.getSelectedIndex();
table_1=jTextField1.getText();
table_2=jTextField2.getText();
// sql="update computer set 名称='"+ table_1 +"' where 地址='"+ table +"'";
sql="update computer set 名称='"+ table_1 +"',机群='"+ table_2 +"',是否开放='"+ system[table_3] +"'where 地址='"+ table +"'";
query(sql);
new chick_ok();
}
}
class updata1_jButton2_actionAdapter implements java.awt.event.ActionListener {
updata1 adaptee;
updata1_jButton2_actionAdapter(updata1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class updata1_jButton1_actionAdapter implements java.awt.event.ActionListener {
updata1 adaptee;
updata1_jButton1_actionAdapter(updata1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -