📄 stationpanel.java~39~
字号:
package traffic;import java.awt.*;import javax.swing.*;import com.borland.dbswing.*;import com.borland.dx.sql.dataset.*;import com.borland.dx.dataset.*;import java.sql.*;import java.awt.event.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class stationPanel extends JPanel { JSplitPane jSplitPane1 = new JSplitPane(); JPanel jPanel1 = new JPanel(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JScrollPane jScrollPane1 = new JScrollPane(); TableScrollPane tableScrollPane1 = new TableScrollPane(); JdbTable jdbTable1 = new JdbTable(); Database database1 = new Database(); QueryDataSet queryDataSet1 = new QueryDataSet(); Column column1 = new Column(); JComboBox jComboBox1 = new JComboBox(); JComboBox jComboBox2 = new JComboBox(); public stationPanel() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { this.setLayout(null); jSplitPane1.setDividerLocation(80); jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT); jSplitPane1.setBounds(new Rectangle(0, 0, 400, 300)); jLabel1.setFont(new java.awt.Font("Serif", 1, 15)); jLabel1.setText("起点站:"); jLabel1.setBounds(new Rectangle(40, 15, 52, 25)); Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); String url = "jdbc:microsoft:sqlserver://keweixing:1433;DatabaseName=dbtraffic"; String username = "sa"; String password = ""; Connection con = DriverManager.getConnection(url,username,password); Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet strs1 = stmt1.executeQuery("select StName from StInfo order by StID"); jComboBox1.setBounds(new Rectangle(92, 15, 80, 25)); jComboBox1.addItem(""); while(strs1.next()){ jComboBox1.addItem(strs1.getString("StName")); } jLabel2.setFont(new java.awt.Font("Serif", 1, 15)); jLabel2.setText("终点站:"); jLabel2.setBounds(new Rectangle(228, 15, 52, 25)); jComboBox2.setBounds(new Rectangle(280, 15, 80, 25)); jComboBox2.addItem(""); strs1.first(); jComboBox2.addItem(strs1.getString("StName")); while(strs1.next()){ jComboBox2.addItem(strs1.getString("StName")); } con.close(); jButton1.setFont(new java.awt.Font("Serif", 1, 12)); jButton1.setText("确定"); jButton1.addActionListener(new stationPanel_jButton1_actionAdapter(this)); jButton1.setBounds(new Rectangle(115, 50, 65, 25)); jButton2.setFont(new java.awt.Font("Serif", 1, 12)); jButton2.setText("清空"); jButton2.setBounds(new Rectangle(220, 50, 65, 25)); database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://keweixing:1433;DatabaseName=dbtraffic", "sa", "", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver")); this.add(jSplitPane1, null); jPanel1.setLayout(null); jPanel1.add(jLabel2, null); jPanel1.add(jLabel1, null); jPanel1.add(jButton1, null); jPanel1.add(jButton2, null); jPanel1.add(jComboBox1, null); jPanel1.add(jComboBox2, null); jSplitPane1.add(jPanel1, JSplitPane.TOP); jSplitPane1.add(jScrollPane1, JSplitPane.BOTTOM); jScrollPane1.getViewport().add(tableScrollPane1, null); tableScrollPane1.getViewport().add(jdbTable1, null); } void jButton1_actionPerformed(ActionEvent e) { queryDataSet1.close(); stQuery = "SELECT BusNum FROM BusSt WHERE (StID = 1+"+jComboBox1.getSelectedIndex()+") AND (BusNum IN (SELECT BusNum FROM BusSt WHERE StID = 1+"+jComboBox2.getSelectedIndex()+"))"; queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, stQuery, null, true, Load.ALL)); column1.setCaption("车次"); column1.setColumnName("BusNum"); column1.setDataType(com.borland.dx.dataset.Variant.INT); column1.setTableName("BusSt"); column1.setServerColumnName("BusNum"); column1.setSqlType(4); queryDataSet1.setColumns(new Column[] {column1}); queryDataSet1.refresh(); jdbTable1.setDataSet(queryDataSet1); } private String stQuery;}class stationPanel_jButton1_actionAdapter implements java.awt.event.ActionListener { stationPanel adaptee; stationPanel_jButton1_actionAdapter(stationPanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -