⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame1.java~26~

📁 火车票的订购系统,实现简单的查阅,定购等功能
💻 JAVA~26~
字号:
package trainticket;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Frame1 extends JFrame {
    JPanel contentPane;
    JLabel jLabel1 = new JLabel();
    JTextField TrainNum = new JTextField();
    ButtonGroup buttonGroup1 = new ButtonGroup();
    JRadioButton RaidaoHard = new JRadioButton();
    JRadioButton RadioSoft = new JRadioButton();
    JTextField OrderNum = new JTextField();
    JButton MainTure = new JButton();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel4 = new JLabel();
    public Frame1() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private void jbInit() throws Exception {
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(null);
        setSize(new Dimension(400, 400));
        setTitle("Frame Title");
        jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel1.setText("订购火车票");
        jLabel1.setBounds(new Rectangle(133, 23, 83, 44));
        TrainNum.setSelectedTextColor(Color.orange);
        TrainNum.setText("");
        TrainNum.setBounds(new Rectangle(175, 100, 125, 33));
        RaidaoHard.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        RaidaoHard.setText("硬座");
        RaidaoHard.setBounds(new Rectangle(161, 175, 91, 25));
        RadioSoft.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        RadioSoft.setText("硬卧");
        RadioSoft.setBounds(new Rectangle(279, 175, 91, 25));
        OrderNum.setSelectedTextColor(Color.orange);
        OrderNum.setBounds(new Rectangle(175, 230, 125, 33));
        MainTure.setBounds(new Rectangle(156, 307, 96, 34));
        MainTure.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        MainTure.setText("确定");
        MainTure.addActionListener(new Frame1_MainTure_actionAdapter(this));
        jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        jLabel2.setText("订购数量:");
        jLabel2.setBounds(new Rectangle(65, 230, 77, 37));
        jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        jLabel3.setText("火车车次:");
        jLabel3.setBounds(new Rectangle(63, 93, 77, 37));
        jLabel4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        jLabel4.setText("乘车方式:");
        jLabel4.setBounds(new Rectangle(64, 165, 77, 37));
        contentPane.add(jLabel1);
        contentPane.add(RaidaoHard);
        contentPane.add(RadioSoft);
        contentPane.add(TrainNum);
        contentPane.add(OrderNum);
        contentPane.add(MainTure);
        contentPane.add(jLabel2);
        contentPane.add(jLabel4);
        contentPane.add(jLabel3);
        buttonGroup1.add(RaidaoHard);
        buttonGroup1.add(RadioSoft);
    }

    public TicketBean tbpaly() {
        TicketBean tb = new TicketBean();
        tb.setTrainNo(TrainNum.getText());
        tb.setSeatNum(Integer.parseInt(OrderNum.getText()));
        tb.setBedNum(Integer.parseInt(OrderNum.getText()));
        return tb;

    }

    public void MainTure_actionPerformed(ActionEvent e) {
        DB db = new DB();
        TicketBean ttb = this.tbpaly();
        if (db.find(ttb)) {
            if(OrderNum.getText()==null || OrderNum.getText().length()<=0)
          {
            JOptionPane.showMessageDialog(this, "请输入订购数量");
          }

            System.out.println(db.checkseat(ttb));
          if (RaidaoHard.isSelected()&&db.checkseat(ttb)==1) {

                System.out.println(ttb.getSeatNum());
                JOptionPane.showMessageDialog(this,
                                              "车票订购成功,请支付" +
                                              (ttb.getSeatPrice() *
                                              ttb.getSeatNum()) + "元");
            }
            if (RadioSoft.isSelected()&&db.checkbed(ttb)==1) {

               JOptionPane.showMessageDialog(this,
                                             "车票订购成功,请支付" +
                                             (ttb.getBedPrice() *
                                             ttb.getBedNum()) + "元");
           }


        } else {
            if (db.checkseat(ttb) == 0 || db.checkbed(ttb) == 0) {
                JOptionPane.showMessageDialog(this, "车票订购失败,原因:车票数量不足", "错误",
                                              JOptionPane.ERROR_MESSAGE);
            }
           if (db.checkseat(ttb) == 2 || db.checkbed(ttb) == 2){
            JOptionPane.showMessageDialog(this, "无此车次");
        }
        JOptionPane.showMessageDialog(this,"订购车票失败");
        }
    }
}


class Frame1_MainTure_actionAdapter implements ActionListener {
    private Frame1 adaptee;
    Frame1_MainTure_actionAdapter(Frame1 adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.MainTure_actionPerformed(e);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -