📄 公交查询系统界面.java
字号:
},
new String [] {
"可搭乘的车次"
}
));
jScrollPane5.setViewportView(jTable3);
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "\u7a0b\u6751", "\u957f\u6625\u9053", "\u8d22\u57ce\u5927\u53a6", "\u627f\u5fb7\u9053", "\u6ca7\u5fb7\u5e84", "\u8d64\u5cf0\u9053", "\u8d64\u5cf0\u6865", "\u5ddd\u5e9c\u65b0\u90a8", "\u7fe0\u961c\u65b0\u6751", "\u5c94\u623f\u5b50", "\u5f69\u8679\u516c\u5bd3", "\u957f\u8679\u516c\u56ed", "\u5f69\u8679\u82b1\u56ed", "\u957f\u534e\u91cc", "\u6f84\u6c5f\u9053 ", "\u957f\u6c5f\u9053", "\u9648\u5bb6\u6c9f\u5b50", "\u6f84\u6c5f\u8def", "\u5d14\u5bb6\u7801\u5934", "\u8d22\u7ecf\u5b66\u9662", "\u57ce\u5efa\u5b66\u9662", "\u6751\u53e3", "\u4ed3\u5e93\u793c\u5802", "\u67f4\u697c", "\u7a0b\u6797\u516c\u5893", "\u6210\u52a8", "\u4ed3\u8054\u5e84", "\u7a0b\u6797\u5e84", "\u5d07\u660e\u8def", "\u5ddd\u5357\u91cc", "\u8336\u68da", "\u4f20\u67d3\u75c5\u9662", "\u4f20\u67d3\u75c5\u533b\u9662", "\u5e38\u719f\u6751", "\u957f\u6c99\u9053", "\u957f\u6c99\u8def", "\u8d64\u571f", "\u8521\u53f0\u6751", "\u957f\u9014\u6c7d\u8f66\u7ad9", "\u957f\u5f81\u533b\u9662", "" }));
org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(51, 51, 51)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jPanel2Layout.createSequentialGroup()
.add(jLabel2)
.add(12, 12, 12)
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 127, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 87, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(29, 29, 29)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(jLabel3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 127, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jButton4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 87, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(jPanel2Layout.createSequentialGroup()
.add(39, 39, 39)
.add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 438, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(43, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(49, 49, 49)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3)
.add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(29, 29, 29)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 17, Short.MAX_VALUE)
.add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 187, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jTabbedPane2.addTab("\u7ad9\u70b9\u67e5\u8be2", jPanel2);
jButton5.setBackground(new java.awt.Color(187, 242, 219));
jButton5.setText("\u9000\u51fa\u516c\u4ea4\u67e5\u8be2\u7cfb\u7edf");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel4Layout.createSequentialGroup()
.add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel4Layout.createSequentialGroup()
.add(201, 201, 201)
.add(jButton5))
.add(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE))
.add(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.add(jTabbedPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.add(jButton5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jTabbedPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jSplitPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// 退出系统
System.exit(0);
}//GEN-LAST:event_jButton5ActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// 站点查询确定
String zdian1 = jComboBox1.getSelectedItem().toString();
String zdian2 = jComboBox2.getSelectedItem().toString();
zdcx(zdian1,zdian2);
//tjh("aa");
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// 站点查询清空
// jComboBox1.setSelectedIndex(0);//显示第一条选项
// jComboBox2.setSelectedIndex(0);
jLabel6.setText("");
scb();
}//GEN-LAST:event_jButton4ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// 车次查询确定
String checi = jTextField1.getText();//判断是否为空还未处理
String xianshi = cccx(checi); //调用车次查询函数
jTextArea1.setText(xianshi); //输出站点信息
this.jTextArea1.setLineWrap(true); //jTextArea1显示内容允许换行
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// 车次查询清空
jTextArea1.setText("");
jTextField1.setText("");
}//GEN-LAST:event_jButton2ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new 公交查询系统界面().setVisible(true);
}
});
}
//连接数据库函数 getResult()
public ResultSet getResult(String sql){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\9 课程设计\\公交车查询系统 -- netbeans\\traffic.mdb";
con = DriverManager.getConnection(url,"","");
stmt = con.createStatement();
ResultSet rs1 = stmt.executeQuery(sql);
return rs1;
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
//车次查询函数 cccx()
public String cccx(String checi){
String xianshi;
try {
rs = getResult("select * from che");
while (rs.next()){
String aa = rs.getString(2);
if(aa.equals(checi)){
xianshi = "\u672c\u6b21\u516c\u4ea4\u7ecf\u8fc7\u4ee5\u4e0b\u7ad9\u70b9\uff1a\n " + rs.getString(3);
//用于记录每个车次经过的站点
return xianshi;
}
}
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
xianshi = "\n\n" + " 没有该车次";
return xianshi;
}
/*public void cxcc(String zd){//查询经过本站点车次
try {
ResultSet rs = getResult("select * from zhan");
while (rs.next()){ //将站点车次保存在数组中
String zhan = rs.getString(2);
if(zhan.equals(zd)){
for (int i = 3;i <11;i++){
String cci = rs.getString(i);
String cc = null;
if(!cci.equals("")){
cc = cci + cc;
}
}
}
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
*/
public void zdcx(String zd1,String zd2){
int data1[] = new int[8];
int data2[] = new int[8];
int i = 0; //用于记录已经查到站点次数,以便优化程序,及时跳出不必要的while循环
try {
ResultSet rs = getResult("select * from zhan");
while (rs.next()){ //将站点车次保存在数组中
String zhan = rs.getString(2);
if(zhan.equals(zd1)){ //经过起始站点车次保存在data1中
i = i + 1;
data1[0] = rs.getInt(3);
data1[1] = rs.getInt(4);
data1[2] = rs.getInt(5);
data1[3] = rs.getInt(6);
data1[4] = rs.getInt(7);
data1[5] = rs.getInt(8);
data1[6] = rs.getInt(9);
data1[7] = rs.getInt(10);
if(zd1.equals(zd2)){
for(int i3 =0;i3<8;i3++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -