已閱讀5頁,還剩20頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
實(shí)驗(yàn)內(nèi)容: 使用JAVA編寫一個(gè)火車票銷售系統(tǒng)完成訂票,改簽,查詢,退票功能。實(shí)驗(yàn)?zāi)康模?通過使用JAVA語言編寫這次火車票銷售系統(tǒng),來完善這學(xué)期所學(xué)習(xí)的JAVA知識(shí)和理論??偨Y(jié)這學(xué)期得學(xué)習(xí)中自己對(duì)各個(gè)知識(shí)點(diǎn)的掌握情況實(shí)驗(yàn)過程:1. 主界面如圖所示: 通過主界面可以實(shí)現(xiàn)訂票,退票,改簽,查詢和退出功能。2. 訂票界面如圖所示: 通過訂票界面我們可以實(shí)現(xiàn)查詢車次,出發(fā)時(shí)間,終點(diǎn)站,軟臥座位,普快火車和車票數(shù)量功能。3. 退票界面如圖所示: 通過退票界面,你可以通過輸入編號(hào)等進(jìn)行退票。討論分析: 這次的編寫讓我們感覺很是吃力,設(shè)置的功能中訂票,查詢等功能因?yàn)閿?shù)據(jù)庫的原因所以有很多都不能使用!但是這是我們組全體的成員的努力的結(jié)晶,在編寫的過程中,我們?nèi)匀粚W(xué)到了很多東西,找到了很多自己掌握不牢和沒掌握的知識(shí)。在這次程序設(shè)計(jì)完成之后,我相信我們會(huì)對(duì)JAVA知識(shí)有一個(gè)更加全面的了解。主要代碼: 數(shù)據(jù)庫連接代碼:package com.qdlg.trainticketmanger.model;import java.sql.Connection;import java.sql.DriverManager;public class DBConnection /* * * return */public static Connection getConn()String url=jdbc:mysql:/localhost:3306/TrainTicketManager;String user=root;String password=;Connection conn = null;try Class.forName(com.mysql.jdbc.Driver); conn=DriverManager.getConnection(url,user,password); return conn; catch (Exception e) e.printStackTrace();return conn;/* * * param args */public static void main(String args) Connection conn = null;conn=getConn();if(conn=null)System.out.println(連接數(shù)據(jù)庫失??!);elseSystem.out.println(連接數(shù)據(jù)庫成功!);界面代碼:package com.qdlg.trainticketmanger.frame;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.Box;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.JToolBar;import javax.swing.border.EtchedBorder;import javax.swing.border.TitledBorder;import javax.swing.JOptionPane;import com.qdlg.trainticketmanger.service.TicketManager;public class BackFrame extends JFrameprivate static final long serialVersionUID = 1L;HandleControlButton handel=new HandleControlButton();JToolBar toolBar=new JToolBar();JButton but_exit=new JButton( EXIT );JButton but_reback = new JButton( 退 票 );JButton but_alter=new JButton( 改 簽 );JTextField ticketNumber=new JTextField(6); JTextField endStation=new JTextField(6);JTextField trainNumber=new JTextField(6); JTextField firstStation=new JTextField(6);public BackFrame() setTitle(火車站售票系統(tǒng)模擬-退票界面);Toolkit toolkit = Toolkit.getDefaultToolkit();Dimension wndSize = toolkit.getScreenSize();setBounds(wndSize.width / 4, wndSize.height / 4, 600,180);setResizable(false);JPanel panel1 = new JPanel();panel1.setBorder(new TitledBorder(new EtchedBorder(), );panel1.add( new JLabel(車票編號(hào):);panel1.add(ticketNumber);panel1.add( new JLabel(車次:);panel1.add(trainNumber);panel1.add( new JLabel(出發(fā)站:);panel1.add(firstStation);panel1.add( new JLabel(到達(dá)站:);panel1.add(endStation);but_reback.addActionListener(handel);but_alter.addActionListener(handel);toolBar.add(but_reback);toolBar.add(but_alter);toolBar.add(but_exit);but_exit.addActionListener(new ActionListener()public void actionPerformed(ActionEvent event) dispose(););ImageIcon imageIcon=new ImageIcon(pictraincheck.gif);JPanel panel2 = new JPanel();panel2.add(new JLabel(imageIcon);Box top=Box.createVerticalBox();top.add(Box.createVerticalStrut(5);top.add(panel2);top.add(Box.createVerticalStrut(2);top.add(panel1);top.add(Box.createGlue();JPanel panel = new JPanel();panel.setBorder(new TitledBorder(new EtchedBorder(), );add(new JLabel( ),BorderLayout.SOUTH);add(top,BorderLayout.CENTER);add(toolBar, BorderLayout.NORTH);add(new JLabel( ), BorderLayout.EAST);add(new JLabel( ), BorderLayout.WEST);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true); class HandleControlButton implements ActionListener public void actionPerformed(ActionEvent e) Object source = e.getSource();if (source = but_reback) TicketManager ticketManager=new TicketManager();boolean isdelete=ticketManager.delete(String)ticketNumber.getText(),(String)trainNumber.getText(); if(isdelete)JOptionPane.showMessageDialog(null,Success,INF, JOptionPane.INFORMATION_MESSAGE);elseJOptionPane.showMessageDialog(null,Fail,INF, JOptionPane.INFORMATION_MESSAGE); else if (source = but_alter) TicketBookFrame ticketBookFrame =new TicketBookFrame();ticketBookFrame.setTicketInf(String)trainNumber.getText(),(String)firstStation.getText(),(String)endStation.getText();ticketBookFrame.showResult();public static void main(String args) new BackFrame();package com.qdlg.trainticketmanger.frame;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.SQLException;import java.util.List;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.JToolBar;import javax.swing.border.EtchedBorder;import javax.swing.border.TitledBorder;import javax.swing.event.TableModelEvent;import javax.swing.event.TableModelListener;import javax.swing.table.DefaultTableModel;import com.qdlg.trainticketmanger.model.Ticket;import com.qdlg.trainticketmanger.model.TicketSale;import com.qdlg.trainticketmanger.model.TrainInf;import com.qdlg.trainticketmanger.service.TicketManager;import com.qdlg.trainticketmanger.service.TicketSaleManager;import com.qdlg.trainticketmanger.service.TrainManager;public class TicketBookFrame extends JFrame implements TableModelListener /* * */private static final long serialVersionUID = 1L;HandleControlButton handel = new HandleControlButton();JToolBar toolBar = new JToolBar();JButton but_exit = new JButton( 關(guān) 閉 );JButton but_select = new JButton( 查 詢 );/JButton but_alter = new JButton( 改 簽 );JButton but_back = new JButton( 退 票 );JButton outTicket = new JButton( 出 票 );JTextField trainNumber = new JTextField(6);/JTextField trainDate = new JTextField(6);JTextField startStation = new JTextField(4);JTextField endStation = new JTextField(4);JComboBox trainDate = new JComboBox();JComboBox grade = new JComboBox();JComboBox type = new JComboBox();JComboBox clientNumber = new JComboBox();Object tableCells = new Object1613;int materialIds = new int21;JTable table;JScrollPane scrollpane;Box top;Box top1 = Box.createVerticalBox();JPanel panel5 = new JPanel();JPanel panel4 = new JPanel();JPanel panel8 = new JPanel();JPanel panel1 = new JPanel();JLabel label_trainNumber = new JLabel(車次: );JLabel label_trainDate = new JLabel(發(fā)車日期: );JLabel label_startStation = new JLabel(出發(fā)站: );JLabel label_endStation = new JLabel(到達(dá)站: );JLabel label_clientNumber = new JLabel(購票數(shù)量: );JLabel label_type = new JLabel(類型: );/學(xué)票/軍人/殘疾/普通JLabel label_grade = new JLabel(級(jí)別: );/軟座/硬座/軟臥/硬臥DefaultTableModel dataModel;int tableRow = 16;/* * 構(gòu)造函數(shù) */public TicketBookFrame() scrollpane = setJTable();for (int i = 0; i 16; i+) tableCellsi0 = i + 1;setTitle(售票界面);Toolkit toolkit = Toolkit.getDefaultToolkit();Dimension wndSize = toolkit.getScreenSize();setBounds(wndSize.width / 8, wndSize.height / 8, 850, 500);/toolBar.add(but_alter);toolBar.add(but_back);toolBar.add(but_select);toolBar.add(outTicket);toolBar.add(but_exit);panel1.add(label_trainNumber);panel1.add(trainNumber);panel1.add(label_trainDate);panel1.add(trainDate);panel1.add(label_startStation);panel1.add(startStation);panel1.add(label_endStation);panel1.add(endStation);panel1.add(label_type);panel1.add(type);panel1.add(label_grade);panel1.add(grade);panel1.add(label_clientNumber);panel1.add(clientNumber);/初始化grade.addItem(硬座);grade.addItem(軟座);grade.addItem(硬臥);grade.addItem(軟臥);type.addItem(普);type.addItem(學(xué));type.addItem(軍);type.addItem(殘);for (int i = 1; i 30; i+) clientNumber.addItem(i);trainDate.addItem(2008.9.+i);top1.setBorder(new TitledBorder(new EtchedBorder(), );JPanel panel2 = new JPanel();JPanel panel3 = new JPanel();panel4.add(new JLabel(- 售 票 界 面 -);top1.add(panel4);top1.add(panel1);top1.add(Box.createVerticalStrut(1);top1.add(panel2);top1.add(panel3);top = Box.createVerticalBox();top.add(Box.createVerticalStrut(10);top.add(top1);panel5.add(new JLabel(- 火 車 票 信 息 統(tǒng) 計(jì) 表 -);top.add(panel5);top.add(scrollpane);top.add(Box.createGlue();but_exit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) dispose(););outTicket.addActionListener(handel);but_select.addActionListener(handel);but_back.addActionListener(handel);add(toolBar, BorderLayout.NORTH);add(top, BorderLayout.CENTER);public void showResult() JButton but_stor = new JButton( 保存 );but_stor.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) dispose(););add(new JLabel( ), BorderLayout.SOUTH);add(new JLabel( ), BorderLayout.EAST);add(new JLabel( ), BorderLayout.WEST);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);public void setTicketInf(String trainNumber1, String startStation1,String endStation1) trainNumber.setText(trainNumber1);startStation.setText(startStation1);endStation.setText(endStation1);public JScrollPane setJTable() dataModel = setTableModel();dataModel.addTableModelListener(this);JTable table = new JTable(dataModel);setTable(table);/給系統(tǒng)屬性賦值/設(shè)置選項(xiàng)得內(nèi)容/List materials=materialManager.findAll();JScrollPane scrollpane = new JScrollPane(table);setScrollpane(scrollpane);return scrollpane;/ 初始化DefaultTableModelpublic DefaultTableModel setTableModel() / TableModeldataModel = new DefaultTableModel() private static final long serialVersionUID = 1L;/ dataModel = new AbstractTableModel() / 獲得Table的列數(shù)public int getColumnCount() return 13;/ 獲得Table的行數(shù)public int getRowCount() return tableRow;/ 返回每一個(gè)表格的內(nèi)容public Object getValueAt(int row, int col) return tableCellsrowcol;public String getColumnName(int column) String colNames = 序號(hào), 車票編號(hào), 車次, 發(fā)車日期, 發(fā)車時(shí)間,出發(fā)站, 到達(dá)站, 價(jià)格, 車廂編號(hào), 座位編號(hào), 類型, 級(jí)別, 售票車站 ;return colNamescolumn;/ 設(shè)置是否可進(jìn)行編輯public boolean isCellEditable(int rowIndex, int columnIndex) if (columnIndex = 0) return false; else return true;public void setValueAt(Object value, int row, int column) fireTableCellUpdated(row, column);return dataModel;public void getTicketInf(List list) /tableCells = new Objectlist.size()9;/this.tableCells=tableCells;/this.tableRow = list.size();for (int i = 0; i list.size(); i+) tableCellsi0 = i + 1;tableCellsi1 = list.get(i).getTicketNumber();tableCellsi2 = trainNumber.getText();tableCellsi3 = list.get(i).getTrainDate();tableCellsi4 = list.get(i).getTrainTime();tableCellsi5 = list.get(i).getStartStation();tableCellsi6 = list.get(i).getEndStation();tableCellsi7 = list.get(i).getPrice();tableCellsi8 = list.get(i).getCarriageNum();tableCellsi9 = list.get(i).getSeatNum();tableCellsi10 = list.get(i).getType();tableCellsi11 = list.get(i).getGrade();tableCellsi12 = 青島;class HandleControlButton implements ActionListener public void actionPerformed(ActionEvent e) Object source = e.getSource();TicketSaleManager ticketSaleManager=new TicketSaleManager();if (source = outTicket) Ticket ticket = new Ticket();ticket.setTrainNumber(trainNumber.getText();/車次ticket.setTrainDate(String)trainDate.getSelectedItem();/日期ticket.setStartStation(startStation.getText();/出發(fā)站ticket.setEndStation(endStation.getText();/終點(diǎn)站ticket.setGrade(String) grade.getSelectedItem();/類型ticket.setType(String) type.getSelectedItem();/人群 ticket.setClientNumber(Integer)clientNumber.getSelectedItem();/票數(shù)量List traininfs = null;TrainManager trainManager = new TrainManager();TicketManager ticketManager = new TicketManager();try Integer userId = ticketManager.findUserId()+1;traininfs = trainManager.findByStation(ticket.getStartStation(), ticket.getEndStation(), ticket.getTrainNumber();/價(jià)格處理if(ticket.getGrade().equals(硬座)ticket.setPrice(Math.abs(traininfs.get(0).getYzprice()- traininfs.get(1).getYzprice();else if(ticket.getGrade().equals(軟座)ticket.setPrice(Math.abs(traininfs.get(0).getRzprice()- traininfs.get(1).getRzprice();else if(ticket.getGrade().equals(硬臥)ticket.setPrice(Math.abs(traininfs.get(0).getYwprice()- traininfs.get(1).getYwprice();else if(ticket.getGrade().equals(軟臥)ticket.setPrice(Math.abs(traininfs.get(0).getRwprice()- traininfs.get(1).getRwprice();if(!ticket.getType().equals(普)ticket.setPrice(ticket.getPrice()/2+1); ticket.setTrainTime(traininfs.get(0).getRestartTime();ticket.setUserId(userId);TicketSale ticketSale=null; for(int i=0 ;i100|ticketSale.getRZSale()100|ticketSale.getYWSale()100|ticketSale.getRWSale()100) ticket.setCarriageNum(0);/無座ticket.setSeatNum(0); else if (ticket.getGrade().equals(硬座) ticket.setCarriageNum(ticketSale.getYZSale()/10+1);ticket.setSeatNum(ticketSale.getYZSale() % 10+1);ticketSale.setYZSale(ticketSale.getYZSale()+1); else if (ticket.getGrade().equals(軟座) ticket.setCarriageNum(ticketSale.getRZSale() / 10+1);ticket.setSeatNum(ticketSale.getRZSale() % 10+1);ticketSale.setRZSale(ticketSale.getRZSale()+1); else if (ticket.getGrade().equals(硬臥) ticket.setCarriageNum(ticketSale.getYWSale() / 10+1);ticket.setSeatNum(ticketSale.getYWSale() % 10+1);ticketSale.setYWSale(ticketSale.getYWSale()+1); else if (ticket.getGrade().equals(軟臥) ticket.setCarriageNum(ticketSale.getRWSale() / 10+1);ticket.setSeatNum(ticketSale.getRWSale() % 10+1);ticketSale.setRWSale(ticketSale.getRWSale()+1); /shezhipiaobianhao ticket.setTicketNumber(00+ticketManager.getIdId();ticketSaleManager.update(ticketSale); ticketManager.addTicket(ticket); /List list = ticketManager.findByUserIdId(userId); TicketBookFrame.this.getContentPane().remove(top);/top.add(setJTable();getTicketInf(list);TicketBookFrame.this.getContentPane().add(top,BorderLayout.CENTER);TicketBookFrame.this.validate();TicketBookFrame.this.repaint(); catch (SQLException e1) e1.printStackTrace();else if(source=but_select)dispose();else if(source=but_back)new BackFrame();dispose();/ 訪問器public JTable getTable() return table;public void setTable(JTable table) this.table = table;public JScrollPane getScrollpane() return scrollpane;public void setScrollpane(JScrollPane scrollpane) this.scrollpane = scrollpane;public int getTableRow() return tableRow;public void setTableRow(int tableRow) this.tableRow = tableRow;public static void main(String args) new TicketBookFrame().showResult();public void tableChanged(TableModelEvent e) / TODO Auto-generated meth
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 蘇科版八年級(jí)物理上冊(cè)《2.3平面鏡》同步測(cè)試題及答案
- 自考財(cái)務(wù)報(bào)表分析重點(diǎn)教學(xué)總結(jié)
- 電子政務(wù)的前景
- 高一化學(xué)達(dá)標(biāo)訓(xùn)練:第一單元化石燃料與有機(jī)化合物
- 2024屆天一大聯(lián)考皖豫聯(lián)盟高考化學(xué)一模試卷含解析
- 2024高中地理第三章區(qū)域自然資源綜合開發(fā)利用章末整合學(xué)案新人教版必修3
- 2024高中物理第四章牛頓運(yùn)動(dòng)定律2實(shí)驗(yàn):探究加速度與力質(zhì)量的關(guān)系課后作業(yè)含解析新人教版必修1
- 2024高中語文第一單元第3課邊城提升訓(xùn)練含解析新人教版必修5
- 2024高中語文精讀課文一第2課2魯迅:深刻與偉大的另一面是平和二課堂練習(xí)含解析新人教版選修中外傳記蚜
- 2024高考化學(xué)二輪復(fù)習(xí)專題限時(shí)集訓(xùn)11有機(jī)化學(xué)基礎(chǔ)含解析
- 水工混凝土規(guī)范
- 圖書館室內(nèi)裝修投標(biāo)方案(技術(shù)標(biāo))
- 工作責(zé)任心測(cè)評(píng)
- 人教精通版5年級(jí)(上下冊(cè))單詞表(含音標(biāo))
- 第1課+中華文明的起源與早期國家+課件+-2023-2024學(xué)年高中歷史統(tǒng)編版2019必修中外歷史綱要上冊(cè)+
- 大廈物業(yè)管理保潔服務(wù)標(biāo)準(zhǔn)5篇
- 神經(jīng)內(nèi)科國家臨床重點(diǎn)??平ㄔO(shè)項(xiàng)目評(píng)分標(biāo)準(zhǔn)(試行)
- 城市設(shè)計(jì)與城市更新培訓(xùn)
- 2023年貴州省銅仁市中考數(shù)學(xué)真題試題含解析
- 世界衛(wèi)生組織生存質(zhì)量測(cè)量表(WHOQOL-BREF)
- PEP-3心理教育量表-評(píng)估報(bào)告
評(píng)論
0/150
提交評(píng)論