1、); JTextField fId = new JTextField(7); JTextField ftid = new JTextField(7); JTextField fche = new JTextField(7); JTextField fzhangshu = new JTextField(7); JTextField fbodyId = new JTextField(7); JPasswordField jpField = new JPasswordField(7); public JPanel getBuypn() JPanel pan = new JPanel(); GridB
2、agLayout layout = new GridBagLayout(); pan.setLayout(layout); GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 100, 100, GridBagConstraints.NONE, GridBagConstraints.WEST); pan.add(buyLabel, con); con = getGridBagConstraints(0, 2, 1, 1, 100, 100, pan.add(new pan3(), con); con = getGridBagCo
3、nstraints(0, 3, 1, 1, 100, 100, pan.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; /* * 定义下面购票操作区面板pan3 * * author Administrator */ class pan3
4、extends JPanel JLabel lId = new JLabel( 车票号码 JLabel ltid = new JLabel( JLabel che = new JLabel( 车 次 JLabel lbodyId = new JLabel( 身份证号 JLabel password = new JLabel( 密码 JLabel lzhangshu = new JLabel( 所需张数 JLabel la1 = new JLabel( JLabel la2 = new JLabel( JButton sureButton = new JButton(查询确认 JButton b
5、uyButton = new JButton(确认购票 public pan3() buyButton.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) UpdateUser(); if (flag=true) UpdateTrain(); System.out.println(hjkasfhjkaf ); sureButton.addActionListener(new ActionListener() select(); GridBagLayout layou
6、t = 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, this.add(fId, con); con = getGridBagConstraints(8, 0, 1, 1, 0, 10
7、0, this.add(la2, con); con = getGridBagConstraints(9, 0, 1, 1, 0, 100, this.add(sureButton, con); con = getGridBagConstraints(0, 1, 1, 1, 0, 100, this.add(ltid, con); con = getGridBagConstraints(1, 1, 1, 1, 0, 100, this.add(ftid, con); con = getGridBagConstraints(2, 1, 1, 1, 0, 100, this.add(che, co
8、n); con = getGridBagConstraints(3, 1, 1, 1, 0, 100, this.add(fche, con); con = getGridBagConstraints(4, 1, 1, 1, 0, 100, this.add(lbodyId, con); con = getGridBagConstraints(5, 1, 1, 1, 0, 100, this.add(fbodyId, con); con = getGridBagConstraints(0, 2, 1, 1, 0, 100, this.add(password, con); con = getG
9、ridBagConstraints(1, 2, 1, 1, 0, 100, this.add(jpField, con); con = getGridBagConstraints(2, 2, 1, 1, 0, 100, this.add(lzhangshu, con); con = getGridBagConstraints(3, 2, 1, 1, 0, 100, this.add(fzhangshu, con); con = getGridBagConstraints(8, 2, 1, 1, 0, 100, this.add(la1, con); con = getGridBagConstr
10、aints(9, 2, 1, 1, 0, 100, this.add(buyButton, con); this.setBorder(BorderFactory.createTitledBorder(订票操作区); * 定义下面一个JList用于显示车票的所有信息面板pan4 class pan4 extends JPanel JButton btId = new JButton(车票号码 JButton bt1 = new JButton(起 点 站 JButton bt2 = new JButton(终 点 站 JButton bt3 = new JButton(车 次 JButton b
11、t4 = new JButton(发车时间 JButton bt5 = new JButton(到达时间 JButton bt6 = new JButton(座位类型 JButton bt7 = new JButton(发车日期 JButton bt8 = new JButton(剩余票数 JButton bt9 = new JButton(车票价格 public pan4() this.setLayout(new GridBagLayout(); this.add(btId, con); this.add(bt1, con); con = getGridBagConstraints(2, 0
12、, 1, 1, 0, 100, this.add(bt2, con); con = getGridBagConstraints(3, 0, 1, 1, 0, 100, this.add(bt3, con); con = getGridBagConstraints(4, 0, 1, 1, 0, 100, this.add(bt4, con); con = getGridBagConstraints(5, 0, 1, 1, 0, 100, this.add(bt5, con); con = getGridBagConstraints(6, 0, 1, 1, 0, 100, this.add(bt6
13、, con); con = getGridBagConstraints(7, 0, 1, 1, 0, 100, this.add(bt7, con); this.add(bt8, con); this.add(bt9, con); con = getGridBagConstraints(0, 1, 11, 1, 0, 100, this.add(jtArea, con); jtArea.setBackground(Color.GREEN); * 定义最下面的按钮面板pan5 class pan5 extends JPanel 退出登录 JLabel lab1 = new JLabel( pub
14、lic pan5() this.add(lab1, con); bt1.addActionListener(new ActionListener() System.exit(0); * 放回一个网格包约束 * param x * param y * param width * param heigh * param weighx * param weighy * param fill * param anchor * return private GridBagConstraints getGridBagConstraints(int x, int y, int width, int heig
15、h, 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 = weighx; con.weighty = weighy; con.fill = fill; con.anchor = anchor; return con; * 按车票号码搜索所有的车票信息 * throws SQL
16、Exception private void select() Connection conn = null; Statement stmt = null; ResultSet ticket = null; try conn = DriverManager.getConnection( jdbc:oracle:thin:127.0.0.1:1521:ORCL, store catch (SQLException e1) e1.printStackTrace(); stmt = conn.createStatement(); String text = select * from train_t
17、able + where tid= + fId.getText() + ; ticket = stmt.executeQuery(text); while (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.g
18、etString(endTime 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+ + starter + + reacher + + ticketNumber + + startTime + + endTime + + seatIdNumber + + busDate + + ticketNum + + price + n jtArea.setText(sb.toString(); if (sb.length() 0) sb.delete(1, sb.length(); else JOptionPane.showMessageDialog(new TestFrame(), 无此车! catch (SQLException e) finally if (ticket != null)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1