📄 informpanel2.java~27~
字号:
package management;import java.awt.*;import javax.swing.*;import com.borland.dbswing.*;import com.borland.dx.sql.dataset.*;import java.sql.*;import com.borland.dx.dataset.*;import com.borland.jbcl.layout.*;import com.borland.dx.sql.dataset.*;import java.awt.event.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class informPanel2 extends JPanel { JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JComboBox jComboBox1 = new JComboBox(); JTextField jTextField1 = new JTextField(); JButton jButton1 = new JButton(); JLabel jLabel3 = new JLabel(); JdbNavToolBar jdbNavToolBar1 = new JdbNavToolBar(); JdbStatusLabel jdbStatusLabel1 = new JdbStatusLabel(); TableScrollPane tableScrollPane1 = new TableScrollPane(); JdbTable jdbTable1 = new JdbTable(); Database database1 = new Database(); QueryDataSet queryDataSet1 = new QueryDataSet(); QueryResolver queryResolver1 = new QueryResolver(); PreparedStatement pstmt; Connection con; String query; ResultSet rs; String str1; String str2; String ip; GridBagLayout gridBagLayout1 = new GridBagLayout(); JButton jButton2 = new JButton(); CheckboxGroup checkboxGroup1 = new CheckboxGroup(); Checkbox checkbox1 = new Checkbox(); Checkbox checkbox2 = new Checkbox(); GridBagLayout gridBagLayout2 = new GridBagLayout(); JLabel jLabel4 = new JLabel(); public informPanel2() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } public informPanel2( String str) { ip=str; try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { jLabel1.setFont(new java.awt.Font("Dialog", 1, 22)); jLabel1.setForeground(SystemColor.activeCaption); jLabel1.setText("选择处理的表:"); this.setLayout(gridBagLayout2); jLabel2.setFont(new java.awt.Font("Dialog", 1, 22)); jLabel2.setForeground(SystemColor.activeCaption); jLabel2.setText("输入学号:"); jComboBox1.addItemListener(new informPanel2_jComboBox1_itemAdapter(this)); jTextField1.setSelectionStart(11); jTextField1.setText(""); jButton1.setBackground(new Color(151, 164, 203)); jButton1.setFont(new java.awt.Font("Dialog", 1, 15)); jButton1.setText("确定"); jButton1.addActionListener(new informPanel2_jButton1_actionAdapter(this)); jLabel3.setFont(new java.awt.Font("Dialog", 1, 22)); jLabel3.setForeground(SystemColor.activeCaption); jLabel3.setText("重置的表"); jdbStatusLabel1.setBackground(new Color(217, 230, 236)); jdbStatusLabel1.setText(""); jdbStatusLabel1.setDataSet(queryDataSet1); database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://"+ip+":1433;DatabaseName=student", "sa", "lomf8244", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver")); database1.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED); queryDataSet1.setResolver(queryResolver1); queryResolver1.setDatabase(database1); queryResolver1.setUpdateMode(com.borland.dx.dataset.UpdateMode.KEY_COLUMNS); jdbTable1.setBackground(new Color(217, 230, 236)); jdbTable1.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); jdbTable1.setSelectionForeground(SystemColor.activeCaptionText); jdbTable1.setDataSet(queryDataSet1); jdbNavToolBar1.setBackground(new Color(217, 230, 236)); jdbNavToolBar1.setForeground(new Color(217, 230, 236)); jdbNavToolBar1.setDataSet(queryDataSet1); jButton2.setBackground(new Color(151, 164, 203)); jButton2.setFont(new java.awt.Font("Dialog", 1, 15)); jButton2.setText("重置"); jButton2.addActionListener(new informPanel2_jButton2_actionAdapter(this)); checkbox1.setBackground(new Color(217, 230, 236)); checkbox1.setCheckboxGroup(checkboxGroup1); checkbox1.setFont(new java.awt.Font("Dialog", 1, 15)); checkbox1.setForeground(Color.black); checkbox1.setLabel("个人信息表"); checkbox1.addItemListener(new informPanel2_checkbox1_itemAdapter(this)); checkbox2.setBackground(new Color(217, 230, 236)); checkbox2.setCheckboxGroup(checkboxGroup1); checkbox2.setFont(new java.awt.Font("Dialog", 1, 15)); checkbox2.setLabel("密码管理表"); checkbox2.addItemListener(new informPanel2_checkbox2_itemAdapter(this)); checkboxGroup1.setSelectedCheckbox(checkbox2); jLabel4.setFont(new java.awt.Font("Dialog", 1, 44)); jLabel4.setForeground(SystemColor.activeCaption); jLabel4.setText(" 学 生 信 息 管 理"); this.setBackground(new Color(217, 230, 236)); tableScrollPane1.getViewport().setBackground(new Color(217, 230, 236)); this.add(jLabel2, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 33, 0, 8), 48, 11)); this.add(jLabel3, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(18, 33, 0, 18), 61, 0)); this.add(jdbNavToolBar1, new GridBagConstraints(0, 5, 4, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(8, 12, 0, 0), 145, 0)); this.add(jdbStatusLabel1, new GridBagConstraints(0, 6, 4, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 10, 0, 16), 485, 0)); this.add(tableScrollPane1, new GridBagConstraints(0, 7, 4, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 52, -244)); this.add(jButton2, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(16, 19, 0, 14), 0, 3)); this.add(jComboBox1, new GridBagConstraints(1, 2, 3, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(21, 26, 0, 19), 247, 5)); this.add(jTextField1, new GridBagConstraints(1, 3, 2, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(22, 29, 0, 9), 175, 4)); this.add(jButton1, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 19, 0, 15), -1, 2)); this.add(checkbox2, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(23, 11, 0, 0), 0, 0)); this.add(checkbox1, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(24, 30, 0, 0), 16, 0)); this.add(jLabel1, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(12, 34, 0, 0), 9, 10)); this.add(jLabel4, new GridBagConstraints(0, 0, 4, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 290, 0)); tableScrollPane1.getViewport().add(jdbTable1, null); jComboBox1.addItem("学生个人信息表"); jComboBox1.addItem("学生密码表"); Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); String url = "jdbc:microsoft:sqlserver://"+ip+":1433;DatabaseName=student"; String username= "sa"; String password= "lomf8244"; con = DriverManager.getConnection(url,username,password); str1="学生密码表"; } void jComboBox1_itemStateChanged(ItemEvent e) { str1=(String)jComboBox1.getSelectedItem(); if(str1.equals("学生个人信息表")) { str1="学生个人信息表"; } else { str1="学生密码表"; } } void jButton1_actionPerformed(ActionEvent e) { try{ if(str1.equals("学生个人信息表")) { query = "select * from student where STUDENTNO=?"; } else { query="select * from usercheck where STUDENTNO=?"; } pstmt = con.prepareStatement(query); pstmt.setString(1,jTextField1.getText()); rs=pstmt.executeQuery(); if(rs.next()){ queryDataSet1.close(); if(str1.equals("学生个人信息表")) { str1 = rs.getString("STUDENTNO"); // str1 ="select STUDENTNO as"+ "\'"+"学号" +"\'"+",STUDENTNAME as" + "\'"+"姓名" +"\'"+",STUDENTAGE as"+ "\'"+"年龄" +"\'"+",STUDENTSEX as"+ "\'"+"性别" +"\'"+",STUENTRACE as"+ "\'"+"民族" +"\'"+",STUDENTSPECIATION as"+ "\'"+"专业" +"\'"+"from student where STUDENTNO="+ "\'" + str1 + "\'"; str1="select * from student where STUDENTNO="+ "\'" + str1 + "\'"; queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, str1, null, true, Load.ALL)); } else { str1 = rs.getString("STUDENTNO"); //str1 ="select STUDENTNO as"+ "\'"+"学号" +"\'"+",PASSWORDS as"+ "\'"+"密码" +"\'"+"from usercheck where STUDENTNO="+ "\'" + str1 + "\'"; str1="select * from usercheck where STUDENTNO="+ "\'" + str1 + "\'"; queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, str1, null, true, Load.ALL)); } queryDataSet1.refresh(); jdbTable1.setDataSet(queryDataSet1); jdbTable1.repaint(); } else{ jTextField1.setText("没有匹配项!"); queryDataSet1.close(); queryDataSet1.refresh(); jdbTable1.setDataSet(null); jdbTable1.repaint(); } } catch(Exception ef) { System.out.print("系统错误,请重新运行。"); } } void jButton2_actionPerformed(ActionEvent e) { jTextField1.setText(""); queryDataSet1.close(); queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, str2, null, true, Load.ALL)); queryDataSet1.refresh(); jdbNavToolBar1.setDataSet(queryDataSet1); jdbStatusLabel1.setDataSet(queryDataSet1); jdbTable1.setDataSet(queryDataSet1); jdbTable1.repaint(); } void checkbox1_itemStateChanged(ItemEvent e) { str2="select * from student"; } void checkbox2_itemStateChanged(ItemEvent e) { str2="select * from usercheck"; }}class informPanel2_jComboBox1_itemAdapter implements java.awt.event.ItemListener { informPanel2 adaptee; informPanel2_jComboBox1_itemAdapter(informPanel2 adaptee) { this.adaptee = adaptee; } public void itemStateChanged(ItemEvent e) { adaptee.jComboBox1_itemStateChanged(e); }}class informPanel2_jButton1_actionAdapter implements java.awt.event.ActionListener { informPanel2 adaptee; informPanel2_jButton1_actionAdapter(informPanel2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}class informPanel2_jButton2_actionAdapter implements java.awt.event.ActionListener { informPanel2 adaptee; informPanel2_jButton2_actionAdapter(informPanel2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}class informPanel2_checkbox1_itemAdapter implements java.awt.event.ItemListener { informPanel2 adaptee; informPanel2_checkbox1_itemAdapter(informPanel2 adaptee) { this.adaptee = adaptee; } public void itemStateChanged(ItemEvent e) { adaptee.checkbox1_itemStateChanged(e); }}class informPanel2_checkbox2_itemAdapter implements java.awt.event.ItemListener { informPanel2 adaptee; informPanel2_checkbox2_itemAdapter(informPanel2 adaptee) { this.adaptee = adaptee; } public void itemStateChanged(ItemEvent e) { adaptee.checkbox2_itemStateChanged(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -