




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、精選優(yōu)質文檔-傾情為你奉上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.Result
2、Set;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 javax.swing.JPasswordField;import javax.swing.JTextArea;import javax.swing.JTextField;publi
3、c class BuyPanel 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);JTextFiel
4、d fzhangshu = new JTextField(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, 10
5、0,GridBagConstraints.NONE, 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);pa
6、n.add(new pan4(), con);con = 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(&
7、quot; 車票號碼 ");JLabel ltid = new JLabel(" 車票號碼 ");JLabel che = new JLabel(" 車 次 ");JLabel lbodyId = new JLabel(" 身份證號 ");JLabel password = new JLabel(" 密碼 ");JLabel lzhangshu = new JLabel(" 所需張數(shù) ");JLabel la1 = new JLabel(" ");JLabel la
8、2 = new JLabel(" ");JButton sureButton = new JButton("查詢確認");JButton buyButton = new JButton("確認購票");public pan3() buyButton.addActionListener(new ActionListener()Overridepublic void actionPerformed(ActionEvent e) UpdateUser();if (flag=true)UpdateTrain();System.out.prin
9、tln("hjkasfhjkaf"););sureButton.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) select(););GridBagLayout layout = new GridBagLayout();this.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100,GridBagConstraints.NONE,
10、GridBagConstraints.EAST);this.add(lId, con);con = getGridBagConstraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fId, con);con = getGridBagConstraints(8, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(la2, con);con = getGridBagConstrai
11、nts(9, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(sureButton, con);con = getGridBagConstraints(0, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(ltid, con);con = getGridBagConstraints(1, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConst
12、raints.EAST);this.add(ftid, con);con = getGridBagConstraints(2, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(che, con);con = getGridBagConstraints(3, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fche, con);con = getGridBagConstraints(4, 1,
13、1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lbodyId, con);con = getGridBagConstraints(5, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fbodyId, con);con = getGridBagConstraints(0, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAS
14、T);this.add(password, con);con = getGridBagConstraints(1, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(jpField, con);con = getGridBagConstraints(2, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lzhangshu, con);con = getGridBagConstraints(3,
15、2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fzhangshu, con);con = getGridBagConstraints(8, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(la1, con);con = getGridBagConstraints(9, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EA
16、ST);this.add(buyButton, con);this.setBorder(BorderFactory.createTitledBorder("訂票操作區(qū)");/* * 定義下面一個JList用于顯示車票的所有信息面板pan4 * * author Administrator * */class pan4 extends JPanel JButton btId = new JButton("車票號碼");JButton bt1 = new JButton("起 點 站");JButton bt2 = new JButton
17、("終 點 站");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("剩余票數(shù)");JButton bt9 = new
18、 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, GridBagConstrain
19、ts.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, 0, 1, 1,
20、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);this.add(bt
21、6, 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,GridBagConstr
22、aints.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 JButton bt1 = n
23、ew 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 = getGridBag
24、Constraints(1, 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
25、weighy * param 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;c
26、on.weightx = 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:127.0.0.1:152
27、1:ORCL", "store", "store"); catch (SQLException e1) e1.printStackTrace();try stmt = conn.createStatement();String text = "select * from train_table " + "where tid=" + "'"+ fId.getText() + "'"ticket = stmt.executeQuery(text);whi
28、le (ticket.next() String starter = ticket.getString("starter");String reacher = ticket.getString("reacher");String ticketNumber = ticket.getString("ticketNumber");String startTime = ticket.getString("startTime");String endTime = ticket.getString("endTime&
29、quot;);String seatIdNumber = ticket.getString("seatIdNumber");String busDate = ticket.getString("busDate");int ticketNum = ticket.getInt("ticketNum");double price = ticket.getDouble("price");sb.append(" " + fId.getText() + "t"+ " "
30、; + starter + "t"+ " " + reacher+ "t"+ " " + ticketNumber + "t" + startTime + "t"+ endTime + "t" + seatIdNumber + "t" + busDate + "t"+ ticketNum + "t" + price + " " + "n");jtArea.s
31、etText(sb.toString();if (sb.length() > 0) sb.delete(1, sb.length(); else JOptionPane.showMessageDialog(new TestFrame(), "無此車!"); catch (SQLException e) finally if (ticket != null) try ticket.close(); catch (SQLException e) e.printStackTrace();if (stmt != null) try stmt.close(); catch (S
32、QLException e) e.printStackTrace();if (conn != null) try conn.close(); catch (SQLException e) e.printStackTrace();/* * 訂票時更新數(shù)據(jù)庫中的車票表 */private void UpdateTrain() String tId=ftid.getText();int num=0;if (fzhangshu.getText().length()>0)num=Integer.parseInt(fzhangshu.getText();Connection conn = Getgb
33、c.getconnect();CallableStatement cst = null;try conn.setAutoCommit(false);cst = conn.prepareCall("call train_proc (?,?)");cst.setString(1, tId);cst.setInt(2, num);cst.execute();mit(); catch (SQLException e1) try conn.rollback();JOptionPane.showMessageDialog(new TestFrame(), "客戶訂票失敗!&q
34、uot;); catch (SQLException e2) JOptionPane.showMessageDialog(new TestFrame(), "客戶訂票失??!"); finally if (cst != null) try cst.close(); catch (SQLException e1) e1.printStackTrace();if (conn != null) try conn.close(); catch (SQLException e1) e1.printStackTrace();/* * 訂票時更新數(shù)據(jù)庫中的用戶表 */private voi
35、d UpdateUser() String tId=ftid.getText();String bId=fbodyId.getText();String cID=fche.getText();String pwd=String.valueOf(jpField.getPassword();int num=0;if(bId.equals(EnterFrame.ID)&&(pwd.equals(EnterFrame.password)if(fzhangshu.getText().length()>0)num=Integer.parseInt(fzhangshu.getText(
36、);Connection conn = Getgbc.getconnect();Statement cst = null;try cst = conn.createStatement();cst.executeUpdate("insert into order_table(tid,id_number,t_num,trainsum)"+ " values('"+ tId+ "','"+ bId+ "','"+ cID + "','"+num+
37、"')");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 !=
38、null) 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 jav
39、a.awt.event.ActionListener;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
40、.JPanel;import javax.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 JTex
41、tField(9);JTextArea 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,GridBagConstrain
42、ts.NONE, GridBagConstraints.WEST);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()
43、, con);con = 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ū)面pan2 * * author Administrator * */class pan2 extends JPanel JLabel trainLabel = new JLabel(" 車 次 &q
44、uot;);JLabel dateLabel = new JLabel(" 日 期 ");JLabel stationLabel = new JLabel(" 起點站 ");JLabel zhiLabel = new JLabel(" 終點站 ");JLabel l1 = new JLabel(" ");JLabel l2 = new JLabel(" ");JButton checkButton = new JButton("查 詢");JButton flushButto
45、n = new JButton("清 空");JPanel panel1 = new JPanel();JPanel panel2 = new JPanel();JTextArea area = new JTextArea();public pan2() flushButton.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) trainField.setText(null);stationField.setText(null);zhiField
46、.setText(null);dateField.setText(null);jtArea.setText(null););checkButton.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) if (dateField.getText().trim().length() > 0) if (trainField.getText().trim().length() > 0| stationField.getText().trim().length()
47、> 0| zhiField.getText().trim().length() > 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"輸入有誤,請檢查輸入位置"); else try dateSelect(); catch (SQLException e1) e1.printStackTrace(); else if (trainField.getText().trim().length() > 0) if (dateField.getText().trim().l
48、ength() > 0| stationField.getText().trim().length() > 0| zhiField.getText().trim().length() > 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"輸入有誤,請檢查輸入位置"); else try idSelect(); catch (SQLException e1) e1.printStackTrace(); else if (stationField.getText().t
49、rim().length() > 0&& zhiField.getText().trim().length() > 0) if (dateField.getText().trim().length() > 0| trainField.getText().trim().length() > 0) jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"輸入有誤,請檢查輸入位置"); else try stationSelect(); catch (SQLEx
50、ception e1) e1.printStackTrace(); else if (dateField.getText().trim().length() <= 0&& stationField.getText().trim().length() <= 0&& zhiField.getText().trim().length() <= 0) if (dateField.getText().trim().length() > 0| stationField.getText().trim().length() > 0| zhiFiel
51、d.getText().trim().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(&quo
52、t;查詢區(qū)");panel2.setBorder(BorderFactory.createTitledBorder("售票注意事項");area.setText( "每人每次最多可夠買十張火車票,超過十張火車票數(shù)的" + "n"+ "請一定要出示您的相關的證件,一旦經(jīng)過售票員查" + "n" + "詢核實并且同意后方可購買");panel2.add(area);GridBagLayout layout = new GridBagLayout();panel1.setLayout(layout);GridBagConstraints con =
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《祝?!贰堆b在套子里的人》聯(lián)讀教學設計-2023-2024學年統(tǒng)編版高中語文必修下冊
- 三基醫(yī)學習題含參考答案
- 2024天津市管道集工程團有限公司公開選聘總法律顧問(兼首席合規(guī)官)筆試參考題庫附帶答案詳解
- 2024國能榆林化工有限公司系統(tǒng)內(nèi)招聘27人筆試參考題庫附帶答案詳解
- 10 奪取抗日戰(zhàn)爭和人民解放戰(zhàn)爭的勝利 第四課時 教學設計-2023-2024學年道德與法治五年級下冊統(tǒng)編版
- 2025年廣東嶺南職業(yè)技術學院單招職業(yè)傾向性測試題庫審定版
- Module 12 Unit 2 教學設計 2024-2025學年外研版九年級英語上冊
- 第二單元《鑒賞“虛”“實”藝術傳承革命精神》大單元教學設計-2024-2025學年統(tǒng)編版高中語文選擇性必修中冊
- 第二單元第5課《分支結構程序設計》教學設計 2023-2024學年浙教版(2020)初中信息技術八年級上冊
- 13 精衛(wèi)填海教學設計-2024-2025學年四年級上冊語文統(tǒng)編版
- 第六章 圍手術期護理課件
- 2024廣東省深圳市寶安區(qū)中考初三二模英語試題及答案
- 中考字音字形練習題(含答案)-字音字形專項訓練
- 音響設備出租行業(yè)競爭分析及發(fā)展前景預測報告
- DB63-T 2313-2024 三江源國家公園生態(tài)監(jiān)測指標
- 2024年湖南高速鐵路職業(yè)技術學院單招職業(yè)適應性測試題庫及答案1套
- 駐場人員服務方案
- C語言程序設計(山東聯(lián)盟-青島科技大學)智慧樹知到答案2024年青島科技大學
- 2024-2029年中國限幅器芯片行業(yè)市場現(xiàn)狀分析及競爭格局與投資發(fā)展研究報告
- 醫(yī)療器械市場規(guī)劃
- 第13課+清前中期的興盛與危機【中職專用】《中國歷史》(高教版2023基礎模塊)
評論
0/150
提交評論