⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jp1.java

📁 java开发的公交查询系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;

public class Jp1 extends JPanel
{
	JPanel jp1,jp2,jp3,jp4,jpl;
	JScrollPane jpr;
	JLabel jl1,jl2,jl3;
	JButton jb1;
	JTextField jt1,jt2;
	JTextArea jta;
	static String array[]=new String[50];
	public Jp1()
	{
		jp1=new JPanel();
		jp2=new JPanel();
		jp3=new JPanel();
		jp4=new JPanel();
		jpl=new JPanel();
		jpr=new JScrollPane();
		jl1=new JLabel("公交换乘查询");
		jl2=new JLabel("起点");
		jl3=new JLabel("终点");
		jl1.setHorizontalAlignment(SwingConstants.CENTER);
		jb1=new JButton("查询");
		jb1.addActionListener(new JBL());
		jt1=new JTextField();
		jt2=new JTextField();
		jta=new JTextArea();
		jta.setLineWrap(true);
		jta.setEditable(false);
		jta.setBorder(jt1.getBorder());
		jt1.setText("包家花园");
		jt2.setText("八一桥");
		jt1.setColumns(10);
		jt2.setColumns(10);
		jl1.setFont(new java.awt.Font("楷体", 0, 12));
		jl2.setFont(new java.awt.Font("楷体", 0, 12));
		jl3.setFont(new java.awt.Font("楷体", 0, 12));
		jb1.setFont(new java.awt.Font("楷体", 0, 12));
		this.setLayout(new GridLayout(1,2));
		jpl.setLayout(new GridLayout(4,1));
		jpr.getViewport().setLayout(new GridLayout(1,1));
		jp1.add(jl1);
		jpl.add(jp1);
		jp2.add(jl2);
		jp2.add(jt1);
		jpl.add(jp2);
		jp3.add(jl3);
		jp3.add(jt2);
		jpl.add(jp3);
		jp4.add(jb1);
		jpl.add(jp4);
		jpr.getViewport().add(jta);
		this.add(jpl);
		this.add(jpr);
	}
	public class JBL implements ActionListener
	{
		public void actionPerformed(ActionEvent e1)
		{
			if(e1.getSource()==jb1)
			{
				String X[]=new String[50];
				String Y[]=new String[50];
				String Z[]=new String[50];
				String O[][]=new String[50][50];
				String P[][]=new String[50][50];
				String W[][]=new String[50][5];
				String R[][][]=new String[50][50][50];
				String G[][][][]=new String[50][50][50][50];
				String S[][]=new String[50][6];
				int lengthofrow_O[]=new int[50];
				int lengthofrow_P[]=new int[50];
				int lengthofrow_R[][]=new int[50][50];
				int lengthofrow_G[][][]=new int[50][50][50];
				int A[]=new int[50];
				int B[]=new int[50];
				int length_X=0,length_Y=0,length_Z=0,length_O=0,length_P=0,length_W=0,length_R=0,length_S=0;
				int i=0,j=0,k=0,l=0,m=0,n=0,temp,a=0,b=0,c=0,d=0;
				String query,stop1,stop2;
				query="select stop_id from stops where stop_name='"+jt1.getText()+"'";
				temp=execute(query);
				stop1=array[0];
				query="select stop_id from stops where stop_name='"+jt2.getText()+"'";
				temp=execute(query);
				stop2=array[0];
				//------------X[]:经过站点一的所有路线
				query="select line_id from linesstops where stop_id IN(select stop_id from stops where stop_name='"+jt1.getText()+"')";
				length_X=execute(query);
				for(j=0;j<length_X;j++)
				{
					X[j]=array[j];
				}
				if(length_X==0)
				{
					System.out.print("没有经过站点一的路线");
				}
				else 
				{
					for(j=0;j<length_X;j++)
					{
						System.out.print("X["+j+"] "+X[j]+" ");
					}
				}
				System.out.println();
				//------------Y[]:经过站点二的所有路线
				query="select line_id from linesstops where stop_id IN(select stop_id from stops where stop_name='"+jt2.getText()+"')";
				length_Y=execute(query);
				j=0;
				for(j=0;j<length_Y;j++)
				{
					Y[j]=array[j];
				}
				if(length_Y==0)
				{
					System.out.print("没有经过站点二的路线");
				}
				else
				{
					for(j=0;j<length_Y;j++)
					{
						System.out.print("Y["+j+"] "+Y[j]+" ");
					}
				}
				System.out.println();
				//------------Z[]:经过站点一与二的所有路线
				if(length_X!=0 && length_Y!=0)
				{
					for(i=0;i<length_X;i++)
					{
						for(j=0;j<length_Y;j++)
						{
							if(X[i].equals(Y[j]))
							{
								Z[k]=X[i];
								k++;
							}
						}
					}
					length_Z=k;
					for(j=0;j<length_Z;j++)
					{
						System.out.print("Z["+j+"] "+Z[j]+" ");
					}
					System.out.println();
					//------------A[]:经过站点一,二,且只要坐一趟车,已按经过站点数目从小到大排序
					for(i=0;i<length_Z;i++)
					{
						int seq1,seq2;
						int length;
						//----------Z[i]路线中站点一的序号
						query="select seq from linesstops where line_id='"+Z[i]+"' and stop_id IN (select stop_id from stops where stop_name ='"+jt1.getText()+"')";
						length=execute(query);
						seq1=Integer.parseInt(array[0]);
						System.out.println("Z["+i+"]:seq1:"+seq1);
						//----------Z[i]路线中站点二的序号
						query="select seq from linesstops where line_id='"+Z[i]+"' and stop_id IN (select stop_id from stops where stop_name ='"+jt2.getText()+"')";
						length=execute(query);
						seq2=Integer.parseInt(array[0]);
						System.out.println("Z["+i+"]:seq2:"+seq2);
						//----------比较两序号,并将差值存入int A[]
						if(seq1>seq2)
						{
							A[i]=seq1-seq2;
						}
						else
						{
							A[i]=seq2-seq1;
						}
					}	
					//----------根据A给Z排序
					bubble(A,Z,length_Z);
					for(j=0;j<length_Z;j++)
					{
						System.out.print("A["+j+"] "+A[j]+" ");
					}
					//----------根据A,列出最佳路线名称
					i=1;
					j=0;
					while (i<length_Z)
					{
						if(A[i-1]<A[i])
						{
							j=i-1;
							break;
						}
						i++;
					}
					System.out.println();
					System.out.print("不需转车的最佳线路:");
					for(i=0;i<=j;i++)
					{
						query="select line_name from lines where line_id ='"+Z[i]+"'";
						int length=execute(query);
						System.out.print(array[0]+" ");
					}
					System.out.println();
					System.out.println("-----------------------");
					query="select line_name from lines where line_id ='"+Z[i]+"'";
					int length=execute(query);
					if(length!=0)
					{
						jta.setText("");
						jta.append("不需转车的最佳线路:\n");
					}
					if(length!=0)
					{
						
						for(i=0;i<=j;i++)
						{
							query="select line_name from lines where line_id ='"+Z[i]+"'";
							int leng=execute(query);
							jta.append(array[0]+" ");
						}
						return;
					}
				}
				//------------O[]路线X(i)所包含的站点
				System.out.println("O[]路线X(i)所包含的站点");
				for(i=0;i<length_X;i++)
				{
					query="select stop_id from linesstops where line_id ='"+X[i]+"'";
					lengthofrow_O[i]=execute(query);
					for(j=0;j<lengthofrow_O[i];j++)
						O[i][j]=array[j];
				}
				for(i=0;i<length_X;i++)
				{
					for(j=0;j<lengthofrow_O[i];j++)
					{
						System.out.println("O["+i+"]["+j+"]:"+O[i][j]+" ");
					}
					System.out.println();
				}
				//--------------P[]路线Y(i)所包含的站点
				System.out.println("P[]路线Y(i)所包含的站点");
				for(i=0;i<length_Y;i++)
				{
					query="select stop_id from linesstops where line_id ='"+Y[i]+"'";
					lengthofrow_P[i]=execute(query);
					for(j=0;j<lengthofrow_P[i];j++)
						P[i][j]=array[j];
				}
				for(i=0;i<length_Y;i++)
				{
					for(j=0;j<lengthofrow_P[i];j++)
					{
						System.out.println("P["+i+"]["+j+"]:"+P[i][j]+" ");
					}
					System.out.println();
				}
				//--------------W[]:o(i,u)=p(j,v)
				System.out.println("W[]:");
				for(i=0;i<length_X;i++)
				{
					for(j=0;j<lengthofrow_O[i];j++)
					{
						for(m=0;m<length_Y;m++)
						{
							for(n=0;n<lengthofrow_P[m];n++)
							{
								if(O[i][j].equals(P[m][n])&&!(X[i].equals(Y[m])))
								{
									for(k=0;k<length_W;k++)
									{
										if(W[k][1].equals(O[i][j]))
										{
											break;
										}
									}
									if(k==length_W && (!(O[i][j]).equals(stop1)) && (!(O[i][j]).equals(stop2)))
									{
										W[length_W][0]=X[i];
										W[length_W][1]=Y[m];
										W[length_W][2]=O[i][j];
										length_W++;
										break;
									}
								}
							}
						}
					}
				}
				for(i=0;i<length_W;i++)
				{
					System.out.println(W[i][0]+" "+W[i][1]+" "+W[i][2]);
				}
				//--------------B[]:经过站点一,二,且只要坐二趟车,已按经过站点数目从小到大排序
				for(i=0;i<length_W;i++)
				{
					int seq1,seq2,seq3,seq4,tempint,seq13,seq24,seq;
					String seq1s,seq2s,seq3s,seq4s,seqs;
					query="select seq from linesstops where line_id='"+W[i][0]+"' and stop_id='"+stop1+"'";
					tempint=execute(query);
					seq1s=array[0];
					query="select seq from linesstops where line_id='"+W[i][1]+"' and stop_id='"+stop2+"'";
					tempint=execute(query);
					seq2s=array[0];
					query="select seq from linesstops where line_id='"+W[i][0]+"' and stop_id='"+W[i][2]+"'";
					tempint=execute(query);
					seq3s=array[0];
					query="select seq from linesstops where line_id='"+W[i][1]+"' and stop_id='"+W[i][2]+"'";
					tempint=execute(query);
					seq4s=array[0];
					seq1=Integer.parseInt(seq1s);
					seq2=Integer.parseInt(seq2s);
					seq3=Integer.parseInt(seq3s);
					seq4=Integer.parseInt(seq4s);
					if(seq1>seq3)
					{
						seq13=seq1-seq3;
					}
					else
					{
						seq13=seq3-seq1;
					}
					if(seq2>seq4)
					{
						seq24=seq2-seq4;
					}
					else
					{
						seq24=seq4-seq2;
					}
					seq=seq13+seq24;
					seqs=Integer.toString(seq);
					W[i][3]=seqs;
				}
				//----------------排序
				int temp1,temp2;
				String temps;
				String temparr[][]=new String[1][4];
				for(int pass=1;pass<length_W;pass++)
				{
					for(i=0;i<length_W-pass;i++)
					{
						temp1=Integer.parseInt(W[i][3]);
						temp2=Integer.parseInt(W[i+1][3]);
						if(temp1>temp2)
						{
							for(j=0;j<4;j++)
							{
								temparr[0][j]=W[i][j];
							}
							for(j=0;j<4;j++)
							{
								W[i][j]=W[i+1][j];
							}
							for(j=0;j<4;j++)
							{
								W[i+1][j]=temparr[0][j];
							}
						}
					}
				}
				//--------------------

⌨️ 快捷键说明

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