




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rè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( 車票號(hào)碼 );JLabel ltid = new
7、JLabel( 車票號(hào)碼 );JLabel che = new JLabel( 車 次 );JLabel lbodyId = new JLabel( 身份證號(hào) );JLabel password = new JLabel( 密碼 );JLabel lzhangshu = new JLabel( 所需張數(shù) );JLabel la1 = new JLabel( );JLabel la2 = new JLabel( );JButton sureButton = new JButton(查詢確認(rèn));JButton buyButton = new JButton(確認(rèn)購票);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ū));/* * 定義下面一個(gè)JList用于顯示車票的所有信息面板pan4 * * author Administrator * */class pan4
16、 extends JPanel JButton btId = new JButton(車票號(hào)碼);JButton bt1 = new JButton(起 點(diǎn) 站);JButton bt2 = new JButton(終 點(diǎn) 站);JButton bt3 = new JButton(車 次);JButton bt4 = new JButton(發(fā)車時(shí)間);JButton bt5 = new JButton(到達(dá)時(shí)間);JButton bt6 = new JButton(座位類型);JButton bt7 = new JButton(發(fā)車日期);JButton bt8 = new JButton(
17、剩余票數(shù));JButton bt9 = new JButton(車票價(jià)格);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););/* * 放回一個(gè)網(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;/* * 按車票號(hào)碼搜索所有的車票信息 * * 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í)更新數(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í)更新數(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(), 您的身份證或密碼有誤!請(qǐng)查證后再訂票); 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( 起點(diǎn)站 );JLabel zhiLabel = new JLabel( 終點(diǎn)站 );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(),輸入有誤,請(qǐng)檢查輸入位置); 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、,請(qǐng)檢查輸入位置); 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(),輸入有誤,請(qǐng)檢查輸入位置); 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(),輸入有誤,請(qǐng)檢查輸入位置); else try allSelect(); catch (SQLException e1) e1.printStackTrace(););JPanel panel3 = new JPanel(new GridBagLayout();panel1.setBorder(BorderFactory.createTitledBorder(查詢區(qū));panel2.setBorder(BorderFactory.
48、createTitledBorder(售票注意事項(xiàng));area.setText( 每人每次最多可夠買十張火車票,超過十張火車票數(shù)的 + n+ 請(qǐng)一定要出示您的相關(guān)的證件,一旦經(jīng)過售票員查 + n + 詢核實(shí)并且同意后方可購買);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等.壓縮文件請(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ī)構(gòu)管理辦法
- 葡萄酒消費(fèi)稅管理辦法
- 宜賓小區(qū)管理辦法細(xì)則
- 規(guī)劃建設(shè)條件管理辦法
- 西安擔(dān)保借貸管理辦法
- 育人故事課件視頻
- 股癬護(hù)理課件視頻教學(xué)
- 壓瘡培訓(xùn)課件5
- 培訓(xùn)課件首頁布局
- 高質(zhì)量高考數(shù)學(xué)試卷
- 倉儲(chǔ)物流部事故應(yīng)急預(yù)案
- 浙江省臺(tái)州市2024-2025學(xué)年高一下學(xué)期期末政治試卷
- 社區(qū)專職考試題庫及答案
- 法院法警考試試題及答案
- 2025年中國電池箔行業(yè)發(fā)展前景預(yù)測及投資戰(zhàn)略研究報(bào)告
- 應(yīng)急工器具培訓(xùn)課件
- 中國食用油市場調(diào)研及發(fā)展策略研究報(bào)告2025-2028版
- 2026屆江蘇省名校新高三6月適應(yīng)性調(diào)研測試語文試題及答案
- 2025年 浙江省考行測考試試題附答案
- JJF 2252-2025機(jī)動(dòng)車檢測用渦流式金屬探傷儀校準(zhǔn)規(guī)范
- 宣傳部密碼電報(bào)管理制度
評(píng)論
0/150
提交評(píng)論