/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package buoi2.jfc;

import javax.swing.JOptionPane;

/**
 *
 * @author student
 */
public class BusReservationFrame extends javax.swing.JFrame {

    /**
     * Creates new form CarTicketBookingJFrame
     */
    public BusReservationFrame() {
        initComponents();
        rad_male.setActionCommand("Nam");
        rad_female.setActionCommand("Nữ");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btgr_sex = new javax.swing.ButtonGroup();
        lbl_num = new javax.swing.JLabel();
        lbl_name = new javax.swing.JLabel();
        lbl_sex = new javax.swing.JLabel();
        lbl_age = new javax.swing.JLabel();
        lbl_addr = new javax.swing.JLabel();
        lbl_phone = new javax.swing.JLabel();
        lbl_route = new javax.swing.JLabel();
        lbl_detime = new javax.swing.JLabel();
        txt_num = new javax.swing.JTextField();
        txt_name = new javax.swing.JTextField();
        rad_male = new javax.swing.JRadioButton();
        rad_female = new javax.swing.JRadioButton();
        cbobox_age = new javax.swing.JComboBox<>();
        scroll_addr = new javax.swing.JScrollPane();
        txt_addr = new javax.swing.JTextArea();
        txt_phone = new javax.swing.JTextField();
        cbobox_route = new javax.swing.JComboBox<>();
        cbobox_detime = new javax.swing.JComboBox<>();
        btn_book = new javax.swing.JButton();
        btn_cancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Đặt vé xe khách");
        setLocationByPlatform(true);
        setResizable(false);

        lbl_num.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_num.setText("STT");

        lbl_name.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_name.setText("Họ và Tên");

        lbl_sex.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_sex.setText("Giới tính");

        lbl_age.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_age.setText("Độ tuổi");

        lbl_addr.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_addr.setText("Địa chỉ");

        lbl_phone.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_phone.setText("Điện thoại");

        lbl_route.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_route.setText("Tuyến đường");

        lbl_detime.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_detime.setText("Giờ khởi hành");

        txt_num.setText("1");
        txt_num.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_numKeyTyped(evt);
            }
        });

        btgr_sex.add(rad_male);
        rad_male.setText("Nam");

        btgr_sex.add(rad_female);
        rad_female.setSelected(true);
        rad_female.setText("Nữ");

        cbobox_age.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "dưới 20", "20 - 30", "30 - 40", "trên 40", " " }));

        txt_addr.setColumns(20);
        txt_addr.setRows(5);
        scroll_addr.setViewportView(txt_addr);

        txt_phone.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_phoneKeyTyped(evt);
            }
        });

        cbobox_route.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Cần Thơ – Sài Gòn", "Cần Thơ – Châu Đốc", " " }));

        cbobox_detime.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "03g45", "06h30" }));

        btn_book.setText("Đặt vé");
        btn_book.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_bookActionPerformed(evt);
            }
        });

        btn_cancel.setText("Hủy bỏ");
        btn_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbl_detime)
                    .addComponent(lbl_route)
                    .addComponent(lbl_phone)
                    .addComponent(lbl_addr)
                    .addComponent(lbl_num)
                    .addComponent(lbl_name)
                    .addComponent(lbl_sex)
                    .addComponent(lbl_age))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rad_male)
                        .addGap(18, 18, 18)
                        .addComponent(rad_female))
                    .addComponent(txt_num, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(scroll_addr, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                    .addComponent(txt_phone)
                    .addComponent(txt_name)
                    .addComponent(cbobox_route, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbobox_age, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbobox_detime, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(30, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btn_book)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btn_cancel)
                .addGap(143, 143, 143))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_num)
                    .addComponent(txt_num, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_name)
                    .addComponent(txt_name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_sex)
                    .addComponent(rad_male)
                    .addComponent(rad_female))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbobox_age, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_age))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(scroll_addr, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_addr))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_phone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_phone))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbobox_route, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_route))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbobox_detime, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_detime))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_book)
                    .addComponent(btn_cancel))
                .addContainerGap(35, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txt_numKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_numKeyTyped
        if (!Character.isDigit(evt.getKeyChar())) {
            evt.consume();
        }
    }//GEN-LAST:event_txt_numKeyTyped

    private void txt_phoneKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_phoneKeyTyped
         if (!Character.isDigit(evt.getKeyChar())) {
            evt.consume();
        }
    }//GEN-LAST:event_txt_phoneKeyTyped

    private void btn_bookActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_bookActionPerformed
        if (txt_num.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Số ghế không được để trống.", "Lỗi", javax.swing.JOptionPane.ERROR_MESSAGE);
            txt_num.requestFocus();
            return;
        }
        if (txt_name.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Họ và Tên không được để trống.", "Lỗi", javax.swing.JOptionPane.ERROR_MESSAGE);
            txt_name.requestFocus();
            return;
        }
        if (txt_addr.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Địa chỉ không được để trống.", "Lỗi", javax.swing.JOptionPane.ERROR_MESSAGE);
            txt_addr.requestFocus();
            return;
        }
        if (txt_phone.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Số điện thoại không được để trống.", "Lỗi", javax.swing.JOptionPane.ERROR_MESSAGE);
            txt_phone.requestFocus();
            return;
        }
        String input = new String();
        input += String.format("%s: %s\n", lbl_num.getText(), txt_num.getText());
        input += String.format("%s: %s\n", lbl_name.getText(), txt_name.getText());
        input += String.format("%s: %s\n", lbl_sex.getText(), btgr_sex.getSelection().getActionCommand());
        input += String.format("%s: %s\n", lbl_addr.getText(), txt_addr.getText());
        input += String.format("%s: %s\n", lbl_phone.getText(), txt_phone.getText());
        input += String.format("%s: %s\n", lbl_route.getText(), cbobox_route.getSelectedItem());
        input += String.format("%s: %s\n", lbl_detime.getText(), cbobox_detime.getSelectedItem());
        System.out.println(input);
        JOptionPane.showMessageDialog(this, input, "Thông tin đặt vé", javax.swing.JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_btn_bookActionPerformed

    private void btn_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelActionPerformed
        txt_num.setText("");
        txt_name.setText("");
        txt_addr.setText("");
        txt_phone.setText("");
    }//GEN-LAST:event_btn_cancelActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BusReservationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BusReservationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BusReservationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BusReservationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BusReservationFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btgr_sex;
    private javax.swing.JButton btn_book;
    private javax.swing.JButton btn_cancel;
    private javax.swing.JComboBox<String> cbobox_age;
    private javax.swing.JComboBox<String> cbobox_detime;
    private javax.swing.JComboBox<String> cbobox_route;
    private javax.swing.JLabel lbl_addr;
    private javax.swing.JLabel lbl_age;
    private javax.swing.JLabel lbl_detime;
    private javax.swing.JLabel lbl_name;
    private javax.swing.JLabel lbl_num;
    private javax.swing.JLabel lbl_phone;
    private javax.swing.JLabel lbl_route;
    private javax.swing.JLabel lbl_sex;
    private javax.swing.JRadioButton rad_female;
    private javax.swing.JRadioButton rad_male;
    private javax.swing.JScrollPane scroll_addr;
    private javax.swing.JTextArea txt_addr;
    private javax.swing.JTextField txt_name;
    private javax.swing.JTextField txt_num;
    private javax.swing.JTextField txt_phone;
    // End of variables declaration//GEN-END:variables
}
