clientframe.java~539~

来自「济南公交管理系统 (不完善,没有解决循环线路问题)」· JAVA~539~ 代码 · 共 1,302 行 · 第 1/4 页

JAVA~539~
1,302
字号
    jMenuBar1.add(jMenu3);
    jMenu1.add(jMenuItem1);
    jMenu1.add(jMenuItem2);
    jMenu3.add(jMenuItem6);
    this.setJMenuBar(jMenuBar1); //显示菜单

    contentPane.add(jPanel1, null);
    jPanel1.add(jLabel13, null);
    jPanel2.add(jTabbedPane1, null);
    jPanel2.add(jPanel8, null);
    contentPane.add(jPanel2, null);

    jPanel9.add(jLabel20, null);
    jPanel9.add(jButton4, null);
    jPanel9.add(jButton7, null);
    jPanel9.add(jLabel23, null);
    jPanel9.add(jButton6, null);
    jPanel9.add(jLabel22, null);
    jPanel9.add(jButton5, null);
    jPanel9.add(jLabel21, null);
    jPanel9.add(jPanel10, null);
    jPanel10.add(jScrollPane5, null);
    jScrollPane5.getViewport().add(jTextArea7, null);
    jPanel9.add(jPanel11, null);
    jPanel11.add(jScrollPane6, null);
    jScrollPane6.getViewport().add(jTextArea8, null);
    jPanel9.add(jPanel12, null);
    jPanel12.add(jScrollPane7, null);
    jScrollPane7.getViewport().add(jTextArea9, null);
    jPanel9.add(jPanel13, null);
    jPanel13.add(jScrollPane8, null);
    jScrollPane8.getViewport().add(jTextArea10, null);

    jPanel6.add(jLabel4, null);
    jPanel6.add(jLabel6, null);
    jPanel6.add(jTextArea6, null);
    jPanel6.add(jLabel12, null);
    jPanel7.add(jLabel5, null);
    jPanel7.add(jScrollPane4, null);

    jTabbedPane1.add(jPanel3, "站点查询");
    jTabbedPane1.add(jPanel4, "线路查询");
    jTabbedPane1.add(jPanel5, "乘车查询");
    jTabbedPane1.add(jPanel6, "公交公司");
    jTabbedPane1.add(jPanel7, "帮助");
    jTabbedPane1.add(jPanel9, "泉城搜刮");

    jPanel8.add(jTextArea5, null);
    jPanel8.add(jLabel7, null);
    jPanel8.add(jLabel8, null);
    jPanel8.add(jLabel9, null);
    jPanel8.add(jLabel10, null);
    jPanel8.add(jLabel11, null);

    //jTabbedPane1.setSelectedIndex(5);
    jTabbedPane1.setSelectedComponent(jPanel9);

  }

  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

  void jMenuItem2_actionPerformed(ActionEvent e) {
    //菜单系统退出
    System.exit(0);
  }

//***************************************************************************//
//*********************判断该车次是否有空调*************************************//
  public boolean shifoukongtiao(int checinum) {
    boolean sfkongtiao = false;
    ResultSet rs;
    try {
      String sql = "select 是否空调 from businfo where 车次号=" + checinum + "";
      rs = con.stmt.executeQuery(sql);
      while (rs.next()) {
        String kongtiao = rs.getString("是否空调").trim();
        if (kongtiao.equals("是")) {
          sfkongtiao = true;
        }
        else
          sfkongtiao = true;
      }
    }
    catch (SQLException e1) {
    }
    return sfkongtiao;
  }

//***************************************************************************//
//****************************站点查询***************************************//
  void jButton1_actionPerformed(ActionEvent e) {
    ResultSet rs;
    jTextArea1.setText("");
    String stationname;
    stationname = jTextField1.getText().trim();
    if (stationname.equals("")) {
      JOptionPane.showMessageDialog(null, "不输入站点名,你查什么啊!");
    }
    else {
      Vector line_vector = bs.search_Station(stationname); //得到通过该站点的线路向量
      int line_size = line_vector.size();
      if (line_size == 0) {
        jTextArea1.setText("");
        jTextArea1.append("仔细想想,是不是要查这个站点!\n");
        jTextArea1.append("以下站点是你想要查的吗?\n");
        //进行模糊查询
        Vector station = bs.search_closeStation(stationname); //对站点进行模糊查询
        int station_size = station.size();
        if (station_size == 0) {
          // 模糊查询失败
          jTextArea1.append("对不起,查询失败!");
        }
        else {
          for (int i = 0; i < station_size; i++) {
            jTextArea1.append(station.get(i).toString() + "\n");
          }
        }
      }
      else {
        //精确查询
        for (int j = 0; j < line_size; j++) {
          jTextArea1.append(line_vector.get(j).toString() + "\n");
        }
      }
    }
  }

//***************************************************************************//
//************************************线路查询*********************************//
  void jButton2_actionPerformed(ActionEvent e) {
    jTextArea2.setText("");
    String linename;
    linename = jTextField4.getText().trim();
    int linenumber;
    linenumber = Integer.parseInt(linename);
    if (linename.equals("")) {
      JOptionPane.showMessageDialog(null, "不输入线路,难道你想坐空气!");
    }
    else {
      //线路属性
      Vector line_info = bs.search_LineProperty(linenumber);
      int line_info_size = line_info.size();
      if (line_info_size == 0) {
        JOptionPane.showMessageDialog(null, "不存在" + linename + "车次");
      }
      else {
        Vector line_pro = (Vector) line_info.get(0);
        String start_station = line_pro.get(0).toString().trim(); //始发站
        String start_time = line_pro.get(1).toString().trim(); //营运时间上
        String end_station = line_pro.get(2).toString().trim(); //终点站
        String end_time = line_pro.get(3).toString().trim(); //营运时间下
        String kongtiao = line_pro.get(4).toString().trim(); //是否空调
        if (kongtiao.equals("是")) {
          //空调车
          jTextArea2.append("k" + linename + "\n");
        }
        else
          jTextArea2.append(linename + "\n");
        jTextArea2.append(start_station);
        jTextArea2.append(start_time + "\n");
        jTextArea2.append(end_station);
        jTextArea2.append(end_time + "\n");
        //线路站点
        Vector line_station_vector = new Vector();
        line_station_vector = bs.search_Linestation(linenumber);
        int line_vector_size = line_station_vector.size();
        Vector line_station = new Vector();
        for (int k = 0; k < line_vector_size; k++) {
          line_station = (Vector) line_station_vector.get(k);
          jTextArea2.append(linename + "    " + line_station.get(0) + "    " +
                            line_station.get(1) + "\n");
          line_station.removeAllElements();
        }
      }
    }
  }

//***************************************************************************//
//*************************乘车方案查询****************************************//
  //******************************************//
  /*String title[] = {
      "先乘车次", "中转站", "换乘车次", "总站数"};
     Vector vector;
     AbstractTableModel tm;
     JTable table;
     TitledBorder titledBorder4;
     //JScrollPane jScrollPane3 = new JScrollPane();*/
  //******************************************//
  void jButton3_actionPerformed(ActionEvent e) {

    String delsql="delete from huancheng";
    try{
      con.stmt.execute(delsql);//清空huancheng表
    }
    catch(SQLException dele)
    {
    }
    jTextArea3.setText(""); //先将上次查询记录清空
    String s1, s2;
    boolean s1cunzai = false, s2cunzai = false;
    s1 = jComboBox1.getSelectedItem().toString().trim();
    s2 = jComboBox2.getSelectedItem().toString().trim();
    String sql = "select * from stationinfo where 站点名='" + s1 + "'";
    String sql1 = "select * from stationinfo where 站点名='" + s2 + "'";
    try {
      ResultSet rs = con.stmt.executeQuery(sql);
      s1cunzai = rs.next();
      rs.close();
      ResultSet rs1 = con.stmt.executeQuery(sql1);
      s2cunzai = rs1.next();
      rs1.close();
    }
    catch (SQLException e1) {
    }
    if (s1.equals("") & s2.equals("")) {
      JOptionPane.showMessageDialog(null, "你从哪来,要到哪去啊?");
    }
    else if (s1.equals("") & !s2.equals("")) {
      JOptionPane.showMessageDialog(null, "你从哪来啊?请输入起始站点!");
    }
    else if (s2.equals("") & !s1.equals("")) {
      JOptionPane.showMessageDialog(null, "你要到哪去啊?请输入终止站点!");
    }
    else {
      if (!s1cunzai | !s2cunzai) {
        JOptionPane.showMessageDialog(null, "输入站点不存在!请先查询站点!");
      }
      else {
        //进行直达查询
        Vector nonstop = bs.search_nonstop(s1, s2);
        int nonstopsize = nonstop.size();
        if (nonstopsize == 0) {
          jTextArea3.append("没有直达方案!!\n");
          //进行一次查询
          Vector first_line;
          Vector change_line;
          Vector change_vector;
          String change_station;
          Vector change_solution = bs.search_oncechange(s1, s2);
          int change_solution_size = change_solution.size();
          if (change_solution_size == 0) {
            jTextArea3.append("不存在直达和一次换乘方案。\n由于计算复杂,请人工查询!");
          }
          else {
            jTextArea3.append("一次换乘方案:\n共有" + change_solution_size + "种\n");
            jTextArea3.append("先乘车次  中转站            换乘车次    总站数\n");
            for (int i = 0; i < change_solution_size; i++) {
              change_vector = (Vector) change_solution.get(i);
              first_line = (Vector) change_vector.get(0); //先乘车次向量
              change_station = change_vector.get(1).toString(); //换乘站点
              change_line = (Vector) change_vector.get(2); //换乘车次向量

              int first_line_size = first_line.size();
              int change_line_size = change_line.size();
              for (int j = 0; j < first_line_size; j++) {
                for (int k = 0; k < change_line_size; k++) {
                  int a = bs.countStation(s1, change_station,
                                          Integer.parseInt(first_line.get(j).
                      toString().trim())); //先乘车次经过的站点数
                  int b = bs.countStation(change_station, s2,
                                          Integer.parseInt(change_line.get(k).
                      toString().trim())); //换乘车次经过的站点数
                  int c = a + b; //经过的总站点数
                  String xianchengcheci=first_line.get(j).toString().trim();//先乘车次
                  String huanchengcheci=change_line.get(k).toString().trim();//换乘车次
                  String insertsql="insert into huancheng values('"+xianchengcheci+"','"+change_station+"','"+huanchengcheci+"',"+c+")";
                  //System.out.println(insertsql);
                  try{
                    con.stmt.execute(insertsql);//将一次换乘方案插入表huancheng中
                  }catch(SQLException inserte){
                  }
                  /*jTextArea3.append(first_line.get(j).toString().trim() +
                                    "        " +
                                    change_station + "" +
                                    change_line.get(k).toString() + "         " +
                                    c + "\n");*/
                }

              }
              //显示出所有的一次换乘方案
              String selsql="select * from huancheng order by 总站数";
              ResultSet selrs;
              try{
                selrs=con.stmt.executeQuery(selsql);
                while(selrs.next())
                {
                  String xiancheng=selrs.getString("先乘车次");
                  String zhongzhuan=selrs.getString("中转站");
                  String huancheng=selrs.getString("换乘车次");
                  int zongzhanshu=selrs.getInt("总站数");
                  jTextArea3.append(xiancheng +
                                    "        " +
                                    zhongzhuan + "" +
                                    huancheng + "         " +
                                    zongzhanshu + "\n");

                }
              }
              catch(SQLException sele){}
            }
          }
          //****************************************************//
          //tm.fireTableStructureChanged(); //更新表格,显示向量vector的内容
          //****************************************************//
        }
        else {
          //输出
          jTextArea3.append("直达方案:\n共有" + nonstopsize + "种方案\n");
          jTextArea3.append("车次    站点数\n");
          for (int i = 0; i < nonstopsize; i++) {
            int a = bs.countStation(s1, s2,
                                    Integer.parseInt(nonstop.get(i).toString())); //经过的站点数
            jTextArea3.append(nonstop.get(i).toString() + "     " + a + "\n");
          }
        }
      }
    }
  }

//***************************************************************************//
//***************************************************************************//

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?