汽车售票系统设计1 引言对课程设计内容做综述,介绍课程设计的目的和要求等内容,并说明采用什么开发工具设计实现一个什么系统等。
实习目的:通过汽车售票系统设计课程设计实习过程,进一步巩固《Java程序设计》课程所学的理论知识,增强学生利用所学内容获取相关知识,以解决实习过程中所面临的问题友好人机界面的布局设置,数据库的连接,Java访问修改数据库, 实现公路汽车售票系统的设计等功能和连接数据库,利用Java访问数据库,以提高利用Java语言实际动手进行程序设计的能力。
上实习要求:能够熟练运用Java,独立设计和编制一个具有一定难度的、解决实际应用问题公路汽车售票系统的设计,包括售票,退票,改签和余票查询等功能2 系统设计(1)需求分析公路汽车售票系统的设计,包括售票,退票,改签和余票查询等功能;友好人机界面(2)总体设计方案1).系统功能结构图2).各子功能的主要算法流程图余票查询和售票:退票:改签:数据库的设计: 票务数据库:用户消息数据库:是否有售票改签不改签是否有售票退票不退票是否有售票退票不退票是否有票售票不售票3 系统实现登陆界面:public class Login extends JFrame implements ActionListener{private JPanel jp =new JPanel();private JLabel[] jlArray={new JLabel ("用户名"),new JLabel ("密码"),new JLabel ("") };private JButton[] jbArray={new JButton ("登陆"),new JButton ("取消")};private JTextField jtxt =new JTextField("小明");private JPasswordField jpassword = new JPasswordField("numberl");String sql;public Login(){jp.setLayout(null);for(int i =0;i<2;i++){jlArray[i].setBounds(30,20+i*50,80,25);jp.add(jlArray[i]);}for(int i =0;i<2;i++){jbArray[i].setBounds(40+i*120,130,100,25);jp.add(jbArray[i]);jbArray[i].addActionListener(this);}jtxt.setBounds(80,20,180,25);jp.add(jtxt);jtxt.addActionListener(this);jpassword.setBounds(80,70,180,25);jp.add(jpassword);jpassword.setEchoChar('*');jpassword.addActionListener(this);jlArray[2].setBounds(10,280,300,25);jp.add(jlArray[2]);this.add(jp);Image image= new ImageIcon("ico.gif").getImage();this.setSize(330,220);this.setIconImage(image);this.setTitle("公路汽车售票系统");this.setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==jtxt){jpassword.requestFocus();}else if(e.getSource()==jbArray[1]){jlArray[1].setText("");jtxt.setText("");jpassword.setText("");jtxt.requestFocus();}else if(e.getSource()==jbArray[0]){sql="select ConName,password from consumer whereConName="+Integer.parseInt(jtxt.getText().trim());try{String ConName="";String password="";jlArray[2].setText("恭喜您,登录成功!!!");new UserSystem();this.dispose();}catch(Exception e1){e1.printStackTrace();}}}public static void main(String[] args){new Login();}}用户公路汽车售票管理界面:public class UserSystem extends JFrame implements ActionListener{DefaultMutableTreeNode[] dmtn={new DefaultMutableTreeNode(new NodeValue("公路汽车售票系统")),new DefaultMutableTreeNode(new NodeValue("售票")),new DefaultMutableTreeNode(new NodeValue("退票")),new DefaultMutableTreeNode(new NodeValue("改签")),new DefaultMutableTreeNode(new NodeValue("余票查询")),new DefaultMutableTreeNode(new NodeValue("退出"))};DefaultTreeModel dtm=new DefaultTreeModel(dmtn[0]);JTree jt= new JTree (dtm);JScrollPane jsp=new JScrollPane(jt);private JSplitPane jsplr=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true); Image image=new ImageIcon("tsgl.jpg").getImage();ImageIcon ii =new ImageIcon(image);private JLabel jlRoot=new JLabel(ii);private JPanel jp=new JPanel();CardLayout cl=new CardLayout();public UserSystem(){this.initJp();jt.addTreeSelectionListener(new TreeSelectionListener() {public void valueChanged(TreeSelectionEvent e){DefaultMutableTreeNodecdmtn=(DefaultMutableTreeNode)e.getPath().getLastPathComponent();NodeValue cnv=(NodeValue)cdmtn.getUserObject();if (cnv.value.equals("公路汽车售票系统")){cl.show(jp,"root");}if (cnv.value.equals("售票")){cl.show(jp,"Buy");}else if (cnv.value.equals("退票")){cl.show(jp,"Return");}else if (cnv.value.equals("改签")){cl.show(jp,"Change");}else if (cnv.value.equals("余票查询")){cl.show(jp,"Ask");}else if (cnv.value.equals("退出")){int i=JOptionPane.showConfirmDialog(UserSystem.this,"是否退出系统?","消息",JOptionPane.YES_NO_OPTION);if (i==JOptionPane.YES_OPTION){System.exit(0);}}}});for(int i=1;i<dmtn.length;i++){dtm.insertNodeInto(dmtn[i], dmtn[0], i-1);}jt.setEditable(false);this.add(jsplr);jsplr.setLeftComponent(jt);jp.setBounds(200, 50, 300, 400);jsplr.setRightComponent(jp);jsplr.setDividerLocation(150);jsplr.setDividerSize(4);jlRoot.setFont(new Font("Courier",Font.PLAIN,30));jlRoot.setHorizontalAlignment(JLabel.CENTER);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Image image= new ImageIcon("ico.gif").getImage();this.setIconImage(image);this.setTitle("公路汽车售票系统");Dimension screenSize= Toolkit.getDefaultToolkit().getScreenSize();int centerX=screenSize.width/2;int centerY=screenSize.height/2;int w=500;int h=400;this.setBounds(centerX-w/2,centerY-h/2-100,w,h);this.setExtendedState(JFrame.MAXIMIZED_BOTH);this.setVisible(true);jt.setShowsRootHandles(true);}public void initJp(){jp.setLayout(cl);jp.add(jlRoot,"root");jp.add(new Buy(),"Buy");jp.add(new Return(),"Return");jp.add(new Change(),"Change");jp.add(new Ask(),"Ask");}public void actionPerformed(ActionEvent e){}public static void main(String[] args){new UserSystem();}}class NodeValue{//声明NodeValue类String value;public NodeValue(String value){this.value=value;}public String getValue(){//声明NodeValue构造器return this.value;}public String toString(){return value;}}售票:public class Buy extends JPanel implements ActionListener { private JSplitPane jsp1=new JSplitPane(JSplitPane.VERTICAL_SPLIT,true);private JPanel jp2=new JPanel();int flag;String sql;DataBase db;private JButton jb2=new JButton("确定");private JLabel jl3=new JLabel("请输入要买的车票");private JTextField jtxt3=new JTextField();Vector<String> head = new Vector<String>(); //创建标题{head.add("票号");head.add("票名");head.add("起点");head.add("终点");head.add("剩余票数");}Vector<Vector> data=new Vector<Vector>();DefaultTableModel dtm=new DefaultTableModel(data,head);JTable jt=new JTable(dtm);JScrollPane jspn=new JScrollPane(jt);public Buy(){this.setLayout(new GridLayout(1,1));jsp1.setTopComponent(jp2);jsp1.setBottomComponent(jspn);jsp1.setDividerLocation(80);jsp1.setDividerSize(4);jp2.setLayout(null);jb2.setBounds(400,30,60,20);jp2.add(jb2);jb2.addActionListener(this);jl3.setBounds(60,30,120,20);jp2.add(jl3);jtxt3.setBounds(200,30,100,20);jp2.add(jtxt3);this.add(jsp1);this.setBounds(10,10,800,600);this.setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==jb2){sql="select * from TICKET where TicketNO="+Integer.parseInt(jtxt3.getText().trim());db=new DataBase();Vector<Vector> vtemp = new Vector<Vector>();}}}退票:public class Return extends JPanel implements ActionListener { DataBase db;String sql;String str;private JSplitPane jsp=new JSplitPane(JSplitPane.VERTICAL_SPLIT,true);private JPanel jpt=new JPanel();private JPanel jpb=new JPanel();private JButton[] jbArray=new JButton[]{new JButton ("退票"),new JButton ("确定")};Vector<String> head = new Vector<String>();{head.add("票号");head.add("票名");head.add("起点");head.add("终点");head.add("剩余票数");}Vector<Vector> data=new Vector<Vector>();DefaultTableModel dtm=new DefaultTableModel(data,head);JTable jt=new JTable(dtm);JScrollPane jspn=new JScrollPane(jt);public Return(){this.setLayout(new GridLayout(1,1));jpt.setLayout(null);jpb.setLayout(null);jbArray[0].setBounds(20,30,100,20);jbArray[1].setBounds(200,30,100,20);for(int i=0;i<2;i++){jpt.add(jbArray[i]);jbArray[i].addActionListener(this);}jsp.setTopComponent(jpt);jsp.setBottomComponent(jspn);jsp.setDividerSize(4);this.add(jsp);jsp.setDividerLocation(80);this.setBounds(10,10,800,600);this.setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==jbArray[1]){Vector<Vector> vtemp = new Vector<Vector>();}if(e.getSource()==jbArray[0]){int row=jt.getSelectedRow();str=(String)jt.getValueAt(row,0);int tno=Integer.parseInt(str);sql="Delete from record where TicketNO="+Integer.parseInt(str);db=new DataBase();sql="update ticket set RemainTicket='+1' where TicketNO="+Integer.parseInt(str);//updateTable();}}public static void main(String[] args){new Return();}}其他改签和余票查询调用方法差不多在此省略。