Untitled

mail@pastecode.io avatar
unknown
java
a month ago
9.6 kB
9
Indexable
Never
import java.awt.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class QLDView extends JFrame {

    public QLDView() {

        this.init();

    }
    private void init() {
        this.setTitle("Quan Ly Diem Thi Vao Lop 10");
        this.setSize(900, 500);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);

// tạo thanh menu
        JMenuBar menuBar = new  JMenuBar();
        this.setJMenuBar(menuBar); // thêm thanh menu vào chương trình

        JMenu menuFile = new JMenu("File");
        menuFile.setFont(new Font("Segoe UI",0, 20 ));
        menuBar.add(menuFile);
        JMenuItem menuOpen = new JMenuItem("Open");
        menuOpen.setFont(new Font("Segoe UI",0, 18));
        menuFile.add(menuOpen);
        JMenuItem menuClose = new JMenuItem("Close");
        menuClose.setFont(new Font("Segoe UI",0, 18));
        menuFile.add(menuClose);
        menuFile.addSeparator(); // thêm dấu gạch ngang ngắn cách các JmenuItem
        JMenuItem menuExit = new JMenuItem("Exit");
        menuExit.setFont(new Font("Segoe UI",0, 18));
        menuFile.add(menuExit);

        JMenu menuAbout = new JMenu("About");
        menuAbout.setFont(new Font("Segoe UI",0, 20 ));
        menuBar.add(menuAbout);
        JMenuItem mntnNewMenuItem = new JMenuItem("About me");
        mntnNewMenuItem.setFont(new Font("Segoe UI",0, 18));
        menuAbout.add(mntnNewMenuItem);


// tạo panel đầu
        JPanel jpanel_1 = new JPanel();
        jpanel_1.setLayout(new GridLayout(1, 6));

        JLabel jlabel_Truong = new JLabel("Trường");
        jlabel_Truong.setFont(new Font("Tahoma", 0, 19));
        jpanel_1.add(jlabel_Truong);

        JComboBox<String> comboBox_Truong = new JComboBox<>();
        comboBox_Truong.setFont(new Font("Tahoma", 0, 19));

        comboBox_Truong.addItem("Truong 1");
        comboBox_Truong.addItem("Truong 2");
        comboBox_Truong.addItem("Truong 3");
        jpanel_1.add(comboBox_Truong);

        JLabel jlabel_SBD = new JLabel("Số Báo Danh");
        jlabel_SBD.setFont(new Font("Tahoma", 0, 19));
        jpanel_1.add(jlabel_SBD);

        JTextField textField_SBD = new JTextField();
        textField_SBD.setFont(new Font("Tahoma", 0, 19));
        textField_SBD.setColumns(8);
        jpanel_1.add(textField_SBD);

        JButton jbutton_Tim = new JButton("Tìm");
        jbutton_Tim.setFont(new Font("Tahoma", 0, 18));
        jpanel_1.add(jbutton_Tim);

        JButton jbutton_HuyTim = new JButton("Hủy tìm");
        jbutton_HuyTim.setFont(new Font("Tahoma", 0, 18));
        jpanel_1.add(jbutton_HuyTim);


// tạo panel thứ 2 mục hiện danh sách có kết nối database
        JPanel jpanel_2 = new JPanel();
        jpanel_2.setLayout(new BorderLayout(800, 20));

        JLabel jlabel_DanhSachThiSinh = new JLabel("Danh sách thông tin thí sinh");
        jlabel_DanhSachThiSinh.setFont(new Font("Tahoma", 0, 19));
        jpanel_2.add(jlabel_DanhSachThiSinh, BorderLayout.NORTH);

        JTable table = new JTable();
        table.setModel(new DefaultTableModel(
                new Object[][] {
                },
                new String[] {
                        "STT", "Số báo danh", "Họ Tên", "Giới tính", "Trường", "NV1", "NV2", "Điểm Văn", "Điểm Toán", "Điểm Anh"
                }
        ));

        DefaultTableModel model1 = (DefaultTableModel) table.getModel();
        // Lấy số lượng hàng hiện tại
        int rowCount = model1.getRowCount();
        // Tạo thêm 4 hàng rỗng
        model1.setRowCount(rowCount + 4);

        //table.setBounds(0, 0, 90, 90);
        JScrollPane scrollPane = new JScrollPane(table);
        jpanel_2.add(scrollPane, BorderLayout.CENTER);

// tạo panel thứ 3 là thông tin thí sinh
        JPanel jpanel_3 = new JPanel();
        jpanel_3.setLayout(new BorderLayout(30, 0));

        // bên trên
        JLabel jlabel_ThongTinThiSinh = new JLabel("Thông tin thí sinh");
        jlabel_ThongTinThiSinh.setFont(new Font("Tahoma", 0, 19));
        jpanel_3.add(jlabel_ThongTinThiSinh, BorderLayout.NORTH);


        //panel bên trái
        JPanel jpanel_benTrai = new JPanel();
        jpanel_benTrai.setLayout(new GridLayout(3, 2));
        jpanel_3.add(jpanel_benTrai, BorderLayout.WEST);

        JLabel jlabel_SoBD = new JLabel("Số Báo Danh");
        jlabel_SoBD.setFont(new Font("Tahoma", 0, 19));
        jpanel_benTrai.add(jlabel_SoBD);
        JTextField textField_SoBD = new JTextField();
        textField_SoBD.setFont(new Font("Tahoma", 0, 19));
        textField_SoBD.setColumns(8);
        jpanel_benTrai.add(textField_SoBD);

        JLabel jlabel_HoTen = new JLabel("Họ và tên");
        jlabel_HoTen.setFont(new Font("Tahoma", 0, 19));
        jpanel_benTrai.add(jlabel_HoTen);
        JTextField textField_HoTen = new JTextField();
        textField_HoTen.setFont(new Font("Tahoma", 0, 19));
        textField_HoTen.setColumns(8);
        jpanel_benTrai.add(textField_HoTen);

        JLabel jlabel_GioiTinh = new JLabel("Giới Tính");
        jlabel_GioiTinh.setFont(new Font("Tahoma", 0, 19));
        jpanel_benTrai.add(jlabel_GioiTinh);
        JPanel jpanel_buttonGroup = new JPanel();
        jpanel_buttonGroup.setLayout(new GridLayout(1, 2));
        JRadioButton jRadioButton_Nam = new JRadioButton("Nam");
        JRadioButton jRadioButton_Nu = new JRadioButton("Nữ");
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(jRadioButton_Nam);
        buttonGroup.add(jRadioButton_Nu);
        jpanel_buttonGroup.add(jRadioButton_Nam);
        jpanel_buttonGroup.add(jRadioButton_Nu);
        jpanel_benTrai.add(jpanel_buttonGroup);


//panel ở giữa
        JPanel jpanel_oGiua = new JPanel();
        jpanel_oGiua.setLayout(new GridLayout(3, 2));  // Modified layout manager
        jpanel_3.add(jpanel_oGiua, BorderLayout.CENTER);

        JLabel jlabel_Truong1 = new JLabel("Trường");
        jlabel_Truong1.setFont(new Font("Tahoma", 0, 19));
        jpanel_oGiua.add(jlabel_Truong1);

        JComboBox comboBox_Truong1 = new JComboBox();
        jpanel_oGiua.add(comboBox_Truong1);

        JLabel jlabel_NV_1 = new JLabel("Nguyện vọng 1");
        jlabel_NV_1.setFont(new Font("Tahoma", 0, 19));
        jpanel_oGiua.add(jlabel_NV_1);

        JComboBox<String> comboBox_NV_1 = new JComboBox<>();
        jpanel_oGiua.add(comboBox_NV_1);

        JLabel jlabel_NV_2 = new JLabel("Nguyện vọng 2");
        jlabel_NV_2.setFont(new Font("Tahoma", 0, 19));
        jpanel_oGiua.add(jlabel_NV_2);

        JComboBox<String> comboBox_NV_2 = new JComboBox<>();
        jpanel_oGiua.add(comboBox_NV_2);

        //panel bên phải
        JPanel jpanel_benPhai = new JPanel();
        jpanel_benPhai.setLayout(new GridLayout(3, 1));
        jpanel_3.add(jpanel_benPhai, BorderLayout.EAST);

        JLabel jlabel_DiemToan = new JLabel("Điểm Toán");
        jlabel_DiemToan.setFont(new Font("Tahoma", 0, 19));
        jpanel_benPhai.add(jlabel_DiemToan);
        JTextField textField_DiemToan = new JTextField();
        textField_DiemToan.setFont(new Font("Tahoma", 0, 19));
        textField_DiemToan.setColumns(8);
        jpanel_benPhai.add(textField_DiemToan);

        JLabel jlabel_DiemVan = new JLabel("Điểm Văn");
        jlabel_DiemVan.setFont(new Font("Tahoma", 0, 19));
        jpanel_benPhai.add(jlabel_DiemVan);
        JTextField textField_DiemVan = new JTextField();
        textField_DiemVan.setFont(new Font("Tahoma", 0, 19));
        textField_DiemVan.setColumns(8);
        jpanel_benPhai.add(textField_DiemVan);

        JLabel jlabel_DiemAnh = new JLabel("Điểm văn");
        jlabel_DiemAnh.setFont(new Font("Tahoma", 0, 19));
        jpanel_benPhai.add(jlabel_DiemAnh);
        JTextField textField_DiemAnh = new JTextField();
        textField_DiemAnh.setFont(new Font("Tahoma", 0, 19));
        textField_DiemAnh.setColumns(8);
        jpanel_benPhai.add(textField_DiemAnh);

        //panel bên dưới
        JPanel jpanel_benDuoi = new JPanel();
        jpanel_benDuoi.setLayout(new GridLayout(1, 5));
        jpanel_3.add(jpanel_benDuoi, BorderLayout.SOUTH);

        JButton jbutton_Them = new JButton("Thêm");
        jbutton_Them.setFont(new Font("Tahoma", 0, 18));
        jpanel_benDuoi.add(jbutton_Them);

        JButton jbutton_Xoa = new JButton("Xóa");
        jbutton_Xoa.setFont(new Font("Tahoma", 0, 18));
        jpanel_benDuoi.add(jbutton_Xoa);

        JButton jbutton_CapNhat = new JButton("Cập nhật");
        jbutton_CapNhat.setFont(new Font("Tahoma", 0, 18));
        jpanel_benDuoi.add(jbutton_CapNhat);

        JButton jbutton_Luu = new JButton("Lưu");
        jbutton_Luu.setFont(new Font("Tahoma", 0, 18));
        jpanel_benDuoi.add(jbutton_Luu);

        JButton jbutton_HuyBo = new JButton("Hủy bỏ");
        jbutton_HuyBo.setFont(new Font("Tahoma", 0, 18));
        jpanel_benDuoi.add(jbutton_HuyBo);


// giao diện chính
        this.setLayout(new BorderLayout());
        this.add(jpanel_1, BorderLayout.NORTH);
        this.add(jpanel_2, BorderLayout.CENTER);
        this.add(jpanel_3, BorderLayout.SOUTH);
        this.setVisible(true);

    }

    public static void main(String[] args) {
        QLDView qldView = new QLDView();
    }
}
Leave a Comment