合作人:张秋亮
已实现功能:后端:能够查询并显示地铁线路 前端:单独显示线路,地铁线路的放大
未实现的功能:悬浮框和站点实时操作
实现功能重要代码:
1 package DJSTL; 2 import util.util; 3 4 import java.sql.Connection; 5 import java.sql.PreparedStatement; 6 import java.sql.ResultSet; 7 import java.sql.SQLException; 8 import java.util.ArrayList; 9 import java.util.HashSet; 10 import java.util.List; 11 import java.util.Scanner; 12 import java.util.Set; 13 14 public class DataBuilder { 15 static Connection conn; 16 static PreparedStatement ps = null; 17 static ResultSet rs; 18 static String sql = "select * from station"; //连接数据库 19 static util ut= new util(); 20 static Scanner in = new Scanner(System.in); 21 static String station_name; 22 23 public static List<Station> line1 = new ArrayList<Station>();//1号线 24 public static List<Station> line2 = new ArrayList<Station>();//2号线 25 public static List<Station> line3 = new ArrayList<Station>();//3号线 26 public static List<Station> line4 = new ArrayList<Station>();//10号线 27 public static List<Station> line5 = new ArrayList<Station>();//s1号线 28 public static List<Station> line6 = new ArrayList<Station>();//s8号线 29 public static Set<List<Station>> lineSet = new HashSet<List<Station>>();//所有线集合 30 public static int totalStaion = 0;//总的站点数量 31 static { 32 String[] line1Arr=new String[29]; 33 String[] line2Arr=new String[37]; 34 String[] line3Arr=new String[34]; 35 String[] line4Arr=new String[18]; 36 String[] line5Arr=new String[21]; 37 String[] line6Arr=new String[19]; 38 //1号线 39 40 try { 41 conn=ut.getConn(); 42 ps=null; 43 ResultSet rs=null; 44 sql="select * from station where Line=?"; 45 ps=conn.prepareStatement(sql); 46 ps.setInt(1, 1); 47 rs=ps.executeQuery(); 48 int i=-1; 49 while(rs.next()) 50 { 51 52 i++; 53 station_name=rs.getString("Name"); 54 line1Arr[i]=station_name; 55 // System.out.println(station_name); 56 57 } 58 59 } 60 catch(SQLException e) 61 { 62 e.printStackTrace(); 63 } 64 finally 65 { 66 try 67 { 68 if(ps!=null)ps.close(); 69 if(conn!=null)conn.close(); 70 } 71 catch(Exception e2) 72 { 73 e2.printStackTrace(); 74 } 75 } 76 try { 77 conn=ut.getConn(); 78 ps=null; 79 ResultSet rs=null; 80 sql="select * from station where Line=?"; 81 ps=conn.prepareStatement(sql); 82 ps.setInt(1, 2); 83 rs=ps.executeQuery(); 84 int i=-1; 85 while(rs.next()) 86 { 87 88 i++; 89 station_name=rs.getString("Name"); 90 line2Arr[i]=station_name; 91 // System.out.println(station_name); 92 93 } 94 } 95 catch(SQLException e) 96 { 97 e.printStackTrace(); 98 } 99 finally 100 { 101 try 102 { 103 if(ps!=null)ps.close(); 104 if(conn!=null)conn.close(); 105 } 106 catch(Exception e2) 107 { 108 e2.printStackTrace(); 109 } 110 } 111 try { 112 conn=ut.getConn(); 113 ps=null; 114 ResultSet rs=null; 115 sql="select * from station where Line=?"; 116 ps=conn.prepareStatement(sql); 117 ps.setInt(1,3); 118 rs=ps.executeQuery(); 119 int i=-1; 120 while(rs.next()) 121 { 122 123 i++; 124 station_name=rs.getString("Name"); 125 line3Arr[i]=station_name; 126 // System.out.println(station_name); 127 128 } 129 } 130 catch(SQLException e) 131 { 132 e.printStackTrace(); 133 } 134 finally 135 { 136 try 137 { 138 if(ps!=null)ps.close(); 139 if(conn!=null)conn.close(); 140 } 141 catch(Exception e2) 142 { 143 e2.printStackTrace(); 144 } 145 } 146 try { 147 conn=ut.getConn(); 148 ps=null; 149 ResultSet rs=null; 150 sql="select * from station where Line=?"; 151 ps=conn.prepareStatement(sql); 152 ps.setInt(1, 4); 153 rs=ps.executeQuery(); 154 int i=-1; 155 while(rs.next()) 156 { 157 158 i++; 159 station_name=rs.getString("Name"); 160 line4Arr[i]=station_name; 161 // System.out.println(station_name); 162 163 } 164 } 165 catch(SQLException e) 166 { 167 e.printStackTrace(); 168 } 169 finally 170 { 171 try 172 { 173 if(ps!=null)ps.close(); 174 if(conn!=null)conn.close(); 175 } 176 catch(Exception e2) 177 { 178 e2.printStackTrace(); 179 } 180 } 181 try { 182 conn=ut.getConn(); 183 ps=null; 184 ResultSet rs=null; 185 sql="select * from station where Line=?"; 186 ps=conn.prepareStatement(sql); 187 ps.setInt(1, 5); 188 rs=ps.executeQuery(); 189 int i=-1; 190 while(rs.next()) 191 { 192 193 i++; 194 station_name=rs.getString("Name"); 195 line5Arr[i]=station_name; 196 // System.out.println(station_name); 197 198 } 199 } 200 catch(SQLException e) 201 { 202 e.printStackTrace(); 203 } 204 finally 205 { 206 try 207 { 208 if(ps!=null)ps.close(); 209 if(conn!=null)conn.close(); 210 } 211 catch(Exception e2) 212 { 213 e2.printStackTrace(); 214 } 215 } 216 try { 217 conn=ut.getConn(); 218 ps=null; 219 ResultSet rs=null; 220 sql="select * from station where Line=?"; 221 ps=conn.prepareStatement(sql); 222 ps.setInt(1, 6); 223 rs=ps.executeQuery(); 224 int i=-1; 225 while(rs.next()) 226 { 227 228 i++; 229 station_name=rs.getString("Name"); 230 line6Arr[i]=station_name; 231 // System.out.println(station_name); 232 233 } 234 } 235 catch(SQLException e) 236 { 237 e.printStackTrace(); 238 } 239 finally 240 { 241 try 242 { 243 if(ps!=null)ps.close(); 244 if(conn!=null)conn.close(); 245 } 246 catch(Exception e2) 247 { 248 e2.printStackTrace(); 249 } 250 } 251 252 for(String s : line1Arr){ 253 line1.add(new Station(s)); 254 } 255 for(int i =0;i<line1.size();i++){ 256 if(i<line1.size()-1){ 257 line1.get(i).next = line1.get(i+1); 258 line1.get(i+1).prev = line1.get(i); 259 } 260 } 261 262 /*******************************************************************************/ 263 //2号线 264 265 for(String s : line2Arr){ 266 line2.add(new Station(s)); 267 } 268 for(int i =0;i<line2.size();i++){ 269 if(i<line2.size()-1){ 270 line2.get(i).next = line2.get(i+1); 271 line2.get(i+1).prev = line2.get(i); 272 } 273 } 274 275 /*******************************************************************************/ 276 //3号线 277 278 for(String s : line3Arr){ 279 line3.add(new Station(s)); 280 } 281 for(int i =0;i<line3.size();i++){ 282 if(i<line3.size()-1){ 283 line3.get(i).next = line3.get(i+1); 284 line3.get(i+1).prev = line3.get(i); 285 } 286 } 287 288 /*******************************************************************************/ 289 //4号线 290 291 for(String s : line4Arr){ 292 line4.add(new Station(s)); 293 } 294 for(int i =0;i<line4.size();i++){ 295 if(i<line4.size()-1){ 296 line4.get(i).next = line4.get(i+1); 297 line4.get(i+1).prev = line4.get(i); 298 } 299 } 300 301 /*******************************************************************************/ 302 //5号线 303 304 for(String s : line5Arr){ 305 line5.add(new Station(s)); 306 } 307 for(int i =0;i<line5.size();i++){ 308 if(i<line5.size()-1){ 309 line5.get(i).next = line5.get(i+1); 310 line5.get(i+1).prev = line5.get(i); 311 } 312 } 313 314 /*******************************************************************************/ 315 //6号线 316 317 for(String s : line6Arr){ 318 line6.add(new Station(s)); 319 } 320 for(int i =0;i<line6.size();i++){ 321 if(i<line6.size()-1){ 322 line6.get(i).next = line6.get(i+1); 323 line6.get(i+1).prev = line6.get(i); 324 } 325 } 326 327 lineSet.add(line1); 328 lineSet.add(line2); 329 lineSet.add(line3); 330 lineSet.add(line4); 331 lineSet.add(line5); 332 lineSet.add(line6); 333 totalStaion = line1.size() + line2.size() + line3.size() + line4.size() + line5.size() + line6.size(); 334 System.out.println("总的站点数量:"+totalStaion); 335 } 336 }