火車售票系統(tǒng)完整代碼_第1頁
火車售票系統(tǒng)完整代碼_第2頁
火車售票系統(tǒng)完整代碼_第3頁
火車售票系統(tǒng)完整代碼_第4頁
火車售票系統(tǒng)完整代碼_第5頁
已閱讀5頁,還剩34頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、package com.yue;import java.awt.Color;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.CallableStatement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import ja

2、va.sql.SQLException;import java.sql.Statement;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextArea;import javax.swing.JTextField;public class BuyPa

3、nel extends JPanel StringBuffer sb = new StringBuffer();private boolean flag = false;JTextArea jtArea = new JTextArea(10, 78);JLabel buyLabel = new JLabel(訂票);JTextField fId = new JTextField(7);JTextField ftid = new JTextField(7);JTextField fche = new JTextField(7);JTextField fzhangshu = new JTextFi

4、eld(7);JTextField fbodyId = new JTextField(7);JPasswordField jpField = new JPasswordField(7);public JPanel getBuypn() JPanel pan = new JPanel();GridBagLayout layout = new GridBagLayout();pan.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 100, 100,GridBagConstraints.NONE

5、, GridBagConstraints.WEST);pan.add(buyLabel, con);con = getGridBagConstraints(0, 2, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan3(), con);con = getGridBagConstraints(0, 3, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan4(), con);co

6、n = getGridBagConstraints(0, 4, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);pan.add(new pan5(), con);this.setLocation(270, 150);this.add(pan);return pan;/* * 定義下面購票操作區(qū)面板pan3 * * author Administrator * */class pan3 extends JPanel JLabel lId = new JLabel( 車票號碼 );JLabel ltid = new

7、JLabel( 車票號碼 );JLabel che = new JLabel( 車 次 );JLabel lbodyId = new JLabel( 身份證號 );JLabel password = new JLabel( 密碼 );JLabel lzhangshu = new JLabel( 所需張數(shù) );JLabel la1 = new JLabel( );JLabel la2 = new JLabel( );JButton sureButton = new JButton(查詢確認);JButton buyButton = new JButton(確認購票);public pan3()

8、buyButton.addActionListener(new ActionListener()Overridepublic void actionPerformed(ActionEvent e) UpdateUser();if (flag=true)UpdateTrain();System.out.println(hjkasfhjkaf););sureButton.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) select(););GridBagLayout

9、layout = new GridBagLayout();this.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lId, con);con = getGridBagConstraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fId, co

10、n);con = getGridBagConstraints(8, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(la2, con);con = getGridBagConstraints(9, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(sureButton, con);con = getGridBagConstraints(0, 1, 1, 1, 0, 100,GridBagCons

11、traints.NONE, GridBagConstraints.EAST);this.add(ltid, con);con = getGridBagConstraints(1, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(ftid, con);con = getGridBagConstraints(2, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(che, con);con = ge

12、tGridBagConstraints(3, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fche, con);con = getGridBagConstraints(4, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lbodyId, con);con = getGridBagConstraints(5, 1, 1, 1, 0, 100,GridBagConstraints.NONE,

13、 GridBagConstraints.EAST);this.add(fbodyId, con);con = getGridBagConstraints(0, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(password, con);con = getGridBagConstraints(1, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(jpField, con);con = getG

14、ridBagConstraints(2, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lzhangshu, con);con = getGridBagConstraints(3, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fzhangshu, con);con = getGridBagConstraints(8, 2, 1, 1, 0, 100,GridBagConstraints.

15、NONE, GridBagConstraints.EAST);this.add(la1, con);con = getGridBagConstraints(9, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(buyButton, con);this.setBorder(BorderFactory.createTitledBorder(訂票操作區(qū));/* * 定義下面一個JList用于顯示車票的所有信息面板pan4 * * author Administrator * */class pan4

16、 extends JPanel JButton btId = new JButton(車票號碼);JButton bt1 = new JButton(起 點 站);JButton bt2 = new JButton(終 點 站);JButton bt3 = new JButton(車 次);JButton bt4 = new JButton(發(fā)車時間);JButton bt5 = new JButton(到達時間);JButton bt6 = new JButton(座位類型);JButton bt7 = new JButton(發(fā)車日期);JButton bt8 = new JButton(

17、剩余票數(shù));JButton bt9 = new JButton(車票價格);public pan4() this.setLayout(new GridBagLayout();GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(btId, con);con = getGridBagConstraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridB

18、agConstraints.EAST);this.add(bt1, con);con = getGridBagConstraints(2, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt2, con);con = getGridBagConstraints(3, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt3, con);con = getGridBagConstraints(4

19、, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt4, con);con = getGridBagConstraints(5, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt5, con);con = getGridBagConstraints(6, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);

20、this.add(bt6, con);con = getGridBagConstraints(7, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt7, con);con = getGridBagConstraints(8, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt8, con);con = getGridBagConstraints(9, 0, 1, 1, 0, 100,Gr

21、idBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt9, con);con = getGridBagConstraints(0, 1, 11, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(jtArea, con);jtArea.setBackground(Color.GREEN);/* * 定義最下面的按鈕面板pan5 * * author Administrator * */class pan5 extends JPanel JBut

22、ton bt1 = new JButton(退出登錄);JLabel lab1 = new JLabel( );public pan5() GridBagLayout layout = new GridBagLayout();this.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt1, con);con = getGridBagConstraints(1

23、, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lab1, con);bt1.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) System.exit(0););/* * 放回一個網(wǎng)格包約束 * * param x * param y * param width * param heigh * param weighx * param weighy * para

24、m fill * param anchor * return */private GridBagConstraints getGridBagConstraints(int x, int y, int width,int heigh, int weighx, int weighy, int fill, int anchor) GridBagConstraints con = new GridBagConstraints();con.gridx = x;con.gridy = y;con.gridwidth = width;con.gridheight = heigh;con.weightx =

25、weighx;con.weighty = weighy;con.fill = fill;con.anchor = anchor;return con;/* * 按車票號碼搜索所有的車票信息 * * throws SQLException */private void select() Connection conn = null;Statement stmt = null;ResultSet ticket = null;try conn = DriverManager.getConnection(jdbc:oracle:thin::1521:ORCL, store, stor

26、e); catch (SQLException e1) e1.printStackTrace();try stmt = conn.createStatement();String text = select * from train_table + where tid= + + fId.getText() + ;ticket = stmt.executeQuery(text);while (ticket.next() String starter = ticket.getString(starter);String reacher = ticket.getString(reacher);Str

27、ing ticketNumber = ticket.getString(ticketNumber);String startTime = ticket.getString(startTime);String endTime = ticket.getString(endTime);String seatIdNumber = ticket.getString(seatIdNumber);String busDate = ticket.getString(busDate);int ticketNum = ticket.getInt(ticketNum);double price = ticket.g

28、etDouble(price);sb.append( + fId.getText() + t+ + starter + t+ + reacher+ t+ + ticketNumber + t + startTime + t+ endTime + t + seatIdNumber + t + busDate + t+ ticketNum + t + price + + n);jtArea.setText(sb.toString();if (sb.length() 0) sb.delete(1, sb.length(); else JOptionPane.showMessageDialog(new

29、 TestFrame(), 無此車!); catch (SQLException e) finally if (ticket != null) try ticket.close(); catch (SQLException e) e.printStackTrace();if (stmt != null) try stmt.close(); catch (SQLException e) e.printStackTrace();if (conn != null) try conn.close(); catch (SQLException e) e.printStackTrace();/* * 訂票

30、時更新數(shù)據(jù)庫中的車票表 */private void UpdateTrain() String tId=ftid.getText();int num=0;if (fzhangshu.getText().length()0)num=Integer.parseInt(fzhangshu.getText();Connection conn = Getgbc.getconnect();CallableStatement cst = null;try conn.setAutoCommit(false);cst = conn.prepareCall(call train_proc (?,?);cst.se

31、tString(1, tId);cst.setInt(2, num);cst.execute();mit(); catch (SQLException e1) try conn.rollback();JOptionPane.showMessageDialog(new TestFrame(), 客戶訂票失敗!); catch (SQLException e2) JOptionPane.showMessageDialog(new TestFrame(), 客戶訂票失??!); finally if (cst != null) try cst.close(); catch (SQLEx

32、ception e1) e1.printStackTrace();if (conn != null) try conn.close(); catch (SQLException e1) e1.printStackTrace();/* * 訂票時更新數(shù)據(jù)庫中的用戶表 */private void UpdateUser() String tId=ftid.getText();String bId=fbodyId.getText();String cID=fche.getText();String pwd=String.valueOf(jpField.getPassword();int num=0;

33、if(bId.equals(EnterFrame.ID)&(pwd.equals(EnterFrame.password)if(fzhangshu.getText().length()0)num=Integer.parseInt(fzhangshu.getText();Connection conn = Getgbc.getconnect();Statement cst = null;try cst = conn.createStatement();cst.executeUpdate(insert into order_table(tid,id_number,t_num,trainsum)+

34、values(+ tId+ ,+ bId+ ,+ cID + ,+num+);JOptionPane.showMessageDialog(new TestFrame(), 客戶訂票成功!);flag=true; catch (SQLException e1) JOptionPane.showMessageDialog(new TestFrame(), 訂票失?。?;flag=false; finally if (cst != null) try cst.close(); catch (SQLException e1) e1.printStackTrace();if (conn != null)

35、 try conn.close(); catch (SQLException e1) e1.printStackTrace();elseJOptionPane.showMessageDialog(new TestFrame(), 您的身份證或密碼有誤!請查證后再訂票); package com.yue;import java.awt.Color;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.Actio

36、nListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import ja

37、vax.swing.JTextArea;import javax.swing.JTextField;public class CheckPanel extends JPanel StringBuffer sb = new StringBuffer();JTextField trainField = new JTextField(9);JTextField dateField = new JTextField(9);JTextField stationField = new JTextField(9);JTextField zhiField = new JTextField(9);JTextAr

38、ea jtArea = new JTextArea(10, 80);JLabel checkLabel = new JLabel(查詢);public JPanel getCheckpn() JPanel pan = new JPanel();GridBagLayout layout = new GridBagLayout();pan.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.W

39、EST);pan.add(checkLabel, con);con = getGridBagConstraints(0, 1, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan2(), con);con = getGridBagConstraints(0, 3, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan4(), con);con = getGridBagConstr

40、aints(0, 4, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);pan.add(new pan5(), con);this.setLocation(270, 150);this.add(pan);return pan;/* * 定義上部查詢區(qū)面pan2 * * author Administrator * */class pan2 extends JPanel JLabel trainLabel = new JLabel( 車 次 );JLabel dateLabel = new JLabel( 日 期

41、);JLabel stationLabel = new JLabel( 起點站 );JLabel zhiLabel = new JLabel( 終點站 );JLabel l1 = new JLabel( );JLabel l2 = new JLabel( );JButton checkButton = new JButton(查 詢);JButton flushButton = new JButton(清 空);JPanel panel1 = new JPanel();JPanel panel2 = new JPanel();JTextArea area = new JTextArea();p

42、ublic pan2() flushButton.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) trainField.setText(null);stationField.setText(null);zhiField.setText(null);dateField.setText(null);jtArea.setText(null););checkButton.addActionListener(new ActionListener() Overridepubl

43、ic void actionPerformed(ActionEvent e) if (dateField.getText().trim().length() 0) if (trainField.getText().trim().length() 0| stationField.getText().trim().length() 0| zhiField.getText().trim().length() 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),輸入有誤,請檢查輸入位置); else try dat

44、eSelect(); catch (SQLException e1) e1.printStackTrace(); else if (trainField.getText().trim().length() 0) if (dateField.getText().trim().length() 0| stationField.getText().trim().length() 0| zhiField.getText().trim().length() 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),輸入有誤

45、,請檢查輸入位置); else try idSelect(); catch (SQLException e1) e1.printStackTrace(); else if (stationField.getText().trim().length() 0& zhiField.getText().trim().length() 0) if (dateField.getText().trim().length() 0| trainField.getText().trim().length() 0) jtArea.setText(null);JOptionPane.showMessageDialog

46、(new TestFrame(),輸入有誤,請檢查輸入位置); else try stationSelect(); catch (SQLException e1) e1.printStackTrace(); else if (dateField.getText().trim().length() = 0& stationField.getText().trim().length() = 0& zhiField.getText().trim().length() 0| stationField.getText().trim().length() 0| zhiField.getText().tri

47、m().length() 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),輸入有誤,請檢查輸入位置); else try allSelect(); catch (SQLException e1) e1.printStackTrace(););JPanel panel3 = new JPanel(new GridBagLayout();panel1.setBorder(BorderFactory.createTitledBorder(查詢區(qū));panel2.setBorder(BorderFactory.

48、createTitledBorder(售票注意事項);area.setText( 每人每次最多可夠買十張火車票,超過十張火車票數(shù)的 + n+ 請一定要出示您的相關(guān)的證件,一旦經(jīng)過售票員查 + n + 詢核實并且同意后方可購買);panel2.add(area);GridBagLayout layout = new GridBagLayout();panel1.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(trainLabel, con);con = getGridBagConstr

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論