秦皇岛公交信息查询系统单机测试平台

上传人:kms****20 文档编号:40704680 上传时间:2018-05-27 格式:DOC 页数:28 大小:140KB
返回 下载 相关 举报
秦皇岛公交信息查询系统单机测试平台_第1页
第1页 / 共28页
秦皇岛公交信息查询系统单机测试平台_第2页
第2页 / 共28页
秦皇岛公交信息查询系统单机测试平台_第3页
第3页 / 共28页
秦皇岛公交信息查询系统单机测试平台_第4页
第4页 / 共28页
秦皇岛公交信息查询系统单机测试平台_第5页
第5页 / 共28页
点击查看更多>>
资源描述

《秦皇岛公交信息查询系统单机测试平台》由会员分享,可在线阅读,更多相关《秦皇岛公交信息查询系统单机测试平台(28页珍藏版)》请在金锄头文库上搜索。

1、/BusSystem.java /秦皇岛公交信息查询系统单机测试平台/用于以窗口形式输入查询站点,输出乘车方案 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.TitledBorder;public class BusSystem extends JFrame implements ActionListenerprivate JTextField jtfBeginSta=new JTextField(10);private JTextField jtfEndS

2、ta=new JTextField(10);private JTextArea jtaResult;private JButton jbtQuery=new JButton(“查询“);public BusSystem()/jtfBeginSta.setHorizontalAlignment(JTextField.RIGHT);/jtfEndSta.setHorizontalAlignment(JTextField.RIGHT);JScrollPane scrollPane=new JScrollPane(jtaResult=new JTextArea();jtaResult.setEdita

3、ble(false);JPanel p1=new JPanel();p1.setLayout(new GridLayout(2,3);p1.add( new Label(“ 起点车站“);p1.add( jtfBeginSta);p1.add( new Label(“ 终点车站“);p1.add( jtfEndSta);JPanel p3=new JPanel();p3.setLayout(new BorderLayout(2,1);p3.add( new Label(“查询结果“),BorderLayout.NORTH);p3.add( scrollPane,BorderLayout.CEN

4、TER );p1.setBorder(new TitledBorder(“ “);JPanel p2=new JPanel();p2.setLayout( new FlowLayout(FlowLayout.RIGHT);p2.add( jbtQuery );getContentPane().add(p1,BorderLayout.NORTH);getContentPane().add(p2,BorderLayout.SOUTH);getContentPane().add(p3,BorderLayout.CENTER);jbtQuery.addActionListener(this);publ

5、ic static void main(String args)BusSystem frame=new BusSystem();frame.setTitle(“秦皇岛公交信息查询系统“);frame.setSize(300,500);frame.setVisible(true);public void actionPerformed(ActionEvent e)if(e.getSource ()=jbtQuery )String beginSta=jtfBeginSta.getText();String endSta=jtfEndSta.getText();String resultQuery

6、;boolean isFinded;Finding_way myFind=new Finding_way();myFind.createFindWay( beginSta,endSta );isFinded=myFind. find_bestway ();if(isFinded)resultQuery=myFind.output();/ System.out.println(myFind.output();elseresultQuery=“对不起,未找到可行方案! n“;jtaResult.setText(resultQuery); /Finding_way.java/该类用来计算乘车方案。i

7、mport .URL; import java.sql.*; public class Finding_way private Beg_end_sta inputstation;/起始站点private Path bestpath;/20 个乘车方案private boolean isfinding;/是否找到可行的乘车方案private int pathTotal;private int errState=0;/1 表示没有直达方案 2 表示起点站与终点站为同一站点/3 表示间接查询中,起点站不存在 5 该车次无车站 /6 倒一次车的中间站点不存在public Finding_way() p

8、ublic Finding_way( Beg_end_sta inputstation,Path bestpath, boolean isfinding )this.inputstation=inputstation;this.bestpath=bestpath;this.isfinding=isfinding;public Finding_way ( Beg_end_sta inputstation )this.inputstation=inputstation;public void createFindWay(Beg_end_sta inputstation)this.inputstat

9、ion=new Beg_end_sta();this.inputstation=inputstation;this.bestpath=new Path20;public void createFindWay(Station begining,Station ending )inputstation=new Beg_end_sta();inputstation.set_be_sta( begining , ending );bestpath=new Path20;for ( int i=0; i0) queryPath=“ “;else queryPath=“ DESC “; /System.o

10、ut.println(queryPath);queryPath=“SELECT station_name FROM bus_table WHERE bus_no=“+resBusNoj+“ AND station_sequence BETWEEN “ +resBegSeq+“ AND “+resEndSeq+“ ORDER BY station_sequence “ +queryPath;/System.out.println(queryPath);resultPassSta=stmt.executeQuery(queryPath);/ResultSetMetaData rsmd=result

11、PassSta.getMetaData();/int numCols=rsmd.getColumnCount();/System.out.print(“ 乘车路线: “+resBusNoj+“路车 方案 “);String busStation;int q=0;while(resultPassSta.next() busStation=resultPassSta.getString(1);/ System.out.print( busStation+“ “);bestpathj.setPassSegment( busStation,q,0);/System.out.print(“ “);q+;

12、/resEndSeq=resultEndSeq.getInt(“station_sequence“);/System.out.println(resEndSeq);resultPassSta.close();/System.out.println(“);/System.out.println(“);/System.out.println(“ “);/ System.out.println(“Create successfully!“);/resultBegSeq.close();/resultEndSeq.close();stmt.close();con.close(); catch(SQLE

13、xception ex)System.out.println(“n*SQLException Caught *n“);while(ex!=null)System.out.println(“ SQLState: “ +ex.getSQLState() ); System.out.println(“ Message: “ +ex.getMessage() );System.out.println(“Vendor: “+ex.getErrorCode();ex=ex.getNextException();System.out.println(“ “); catch(java.lang.Excepti

14、on ex )ex.printStackTrace(); return true; /给出倒一次车的,间接到达方案public boolean indirect_find()String begining=inputstation.getBegName();String ending=inputstation.getEndName(); String queBegBusNo=“SELECT bus_no FROM bus_table WHERE station_name=“+begining+“;String queEndBusNo=“SELECT bus_no FROM bus_table

15、WHERE station_name=“+ending+“;String begBusNo=new String 20;String endBusNo=new String 20; String midBusSta=new String 20; int i=0,j=0; /System.out.println(queBegBusNo);tryClass.forName(“sun.jdbc.odbc.JdbcOdbcDriver“);Connection con=DriverManager.getConnection(“jdbc:odbc:bus“);Statement stmt;stmt=con.createStatement();ResultSet resultBegBusNo,resultEndBusNo;/经过起始站点的线路名称resultBegBusNo=stmt.executeQuery( queBegBusNo );if( !resultBegBusNo.next() )/System.out.println(resBusNo0+“dd“);/间接查询中,起点站不存在,为错误三errState=3; return false;elsebegBusNoi=

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号