Buổi 1:
public class BaiTap3 {
public static void main(String[] args) {
JFrame frm = new JFrame("Tinh Tong, Tich, Hieu");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new BoxLayout([Link](), BoxLayout.Y_AXIS));
[Link](300, 200);
[Link](null);
JPanel pnTieuDe = new JPanel();
[Link](new FlowLayout());
JLabel lbTieuDe = new JLabel("Tinh Luong Nhan Vien: ");
[Link](lbTieuDe);
JPanel pnNhapLieu = new JPanel();
[Link](new GridLayout(3,2));
JLabel lbLuongNgay = new JLabel("Luong Mot Ngay: ");
JTextField txtLuongNgay = new JTextField(15);
[Link](lbLuongNgay); [Link](txtLuongNgay);
JLabel lbNgayCong = new JLabel("Ngay Cong: ");
JTextField txtNgayCong = new JTextField(15);
[Link](lbNgayCong); [Link](txtNgayCong);
JLabel lbLuongThang = new JLabel("Luong Thang: ");
JTextField txtLuongThang = new JTextField(15);
[Link](lbLuongThang); [Link](txtLuongThang);
JPanel pnNutLenh = new JPanel();
[Link](new FlowLayout());
JButton BtnTinh = new JButton("Tinh");
[Link](new ImageIcon ("Hinh/[Link]"));
[Link](BtnTinh);
JButton BtnXoa = new JButton("Xoa");
[Link](new ImageIcon ("Hinh/[Link]"));
[Link](BtnXoa);
JButton BtnThoat = new JButton("Thoat");
[Link](new ImageIcon ("Hinh/[Link]"));
[Link](BtnThoat);
[Link](pnTieuDe);
[Link](pnNhapLieu);
[Link](pnNutLenh);
[Link](true)}}
public class BaiTap4 {
public static void main(String[] args) {
JFrame frm = new JFrame("Giai Phuong Trinh");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new BoxLayout([Link](), BoxLayout.Y_AXIS));
[Link](300, 200);
[Link](null);
JPanel pnTieuDe = new JPanel();
[Link](new FlowLayout());
JLabel lbTieuDe = new JLabel("Giai Phuong Trinh Bac 1: ");
[Link](lbTieuDe);
JPanel pnNhapLieu = new JPanel();
[Link](new GridLayout(3,2));
JLabel lbHeSoA = new JLabel("He So a: ");
JTextField txtHeSoA = new JTextField(15);
[Link](lbHeSoA); [Link](txtHeSoA);
JLabel lbHeSoB = new JLabel("He So b: ");
JTextField txtHeSoB = new JTextField(15);
[Link](lbHeSoB); [Link](txtHeSoB);
// Panel Button
JPanel pnNutLenh = new JPanel();
[Link](new FlowLayout());
JButton BtnTinh = new JButton("Giai");
[Link](BtnTinh);
JButton BtnXoa = new JButton("Thoat");
[Link](BtnXoa);
JButton BtnThoat = new JButton("Moi");
[Link](BtnThoat);
[Link](pnTieuDe);
[Link](pnNhapLieu);
[Link](pnNutLenh);
[Link](true);
}}
Buổi 2:
public class bt1 {
private JFrame frmHinThngBo;
/**
* Launch the application.
*/
public static void main(String[] args) {
[Link](new Runnable() {
public void run() {
try {
bt1 window = new bt1();
[Link](true);
} catch (Exception e) {
[Link]();
}
}
});
}
/**
* Create the application.
*/
public bt1() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmHinThngBo = new JFrame();
[Link]("HI\u1EC6N TH\u00D4NG B\u00C1O");
[Link](100, 100, 450, 300);
[Link](JFrame.EXIT_ON_CLOSE);
[Link]().setLayout(new
BoxLayout([Link](), BoxLayout.Y_AXIS));
JPanel panel = new JPanel();
[Link]([Link]);
[Link]().add(panel);
JLabel lblNewLabel = new JLabel("CH\u01AF\u01A0NG TR\u00CCNH HI\u1EC6N
TH\u00D4NG B\u00C1O");
[Link]([Link]);
[Link](new Font("Tahoma", [Link], 20));
[Link](lblNewLabel);
JPanel panel_1 = new JPanel();
[Link]().add(panel_1);
JButton btnNewButton = new JButton("HI\u1EC2N TH\u1ECA");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
[Link](null, "Chào các bạn!!!");
}
});
[Link](new Font("Tahoma", [Link], 12));
panel_1.add(btnNewButton);
JButton btnNewButton_1 = new JButton("\u0110\u00D3NG C\u1EECA S\u1ED4");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link](0);
}
});
btnNewButton_1.setFont(new Font("Tahoma", [Link], 11));
panel_1.add(btnNewButton_1);
}
}
public class bt2 {
private JFrame frmTmSLn;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
/**
* Launch the application.
*/
public static void main(String[] args) {
[Link](new Runnable() {
public void run() {
try {
bt2 window = new bt2();
[Link](true);
} catch (Exception e) {
[Link]();
}
}
});
}
/**
* Create the application.
*/
public bt2() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmTmSLn = new JFrame();
[Link](new Font("Dialog", [Link] | [Link], 20));
[Link]("T\u00CCM S\u1ED0 L\u1EDAN NH\u1EA4T TRONG BA S\
u1ED0");
[Link](100, 100, 450, 290);
[Link](JFrame.EXIT_ON_CLOSE);
[Link]().setLayout(new
BoxLayout([Link](), BoxLayout.Y_AXIS));
JPanel panel = new JPanel();
[Link]().add(panel);
JLabel lblNewLabel = new JLabel("T\u00CCM S\u1ED0 L\u1EDAN NH\u1EA4T
TRONG BA S\u1ED0");
[Link](new Font("Tahoma", [Link], 20));
[Link](lblNewLabel);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new LineBorder(new Color(0, 0, 0), 2));
[Link]().add(panel_1);
panel_1.setLayout(new GridLayout(3, 2, 20, 10));
JLabel lblNewLabel_1 = new JLabel("S\u1ED1 th\u1EE9 t\u1EF1 1:");
panel_1.add(lblNewLabel_1);
textField = new JTextField();
panel_1.add(textField);
[Link](10);
JLabel lblNewLabel_2 = new JLabel("S\u1ED1 th\u1EE9 t\u1EF1 2:");
panel_1.add(lblNewLabel_2);
textField_1 = new JTextField();
panel_1.add(textField_1);
textField_1.setColumns(10);
JLabel lblNewLabel_3 = new JLabel("S\u1ED1 th\u1EE9 t\u1EF1 3:");
panel_1.add(lblNewLabel_3);
textField_2 = new JTextField();
panel_1.add(textField_2);
textField_2.setColumns(10);
JPanel panel_2 = new JPanel();
[Link]().add(panel_2);
JButton btnNewButton = new JButton("Th\u1EF1c hi\u1EC7n");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
double lblNewLabel_1 = [Link]([Link]());
double lblNewLabel_2 = [Link](textField_1.getText());
double lblNewLabel_3 = [Link](textField_2.getText());
double max = lblNewLabel_1;
if (max < lblNewLabel_2 ) max = lblNewLabel_2;
if (max < lblNewLabel_3 ) max = lblNewLabel_3;
textField_3.setText([Link](max));
}
});
[Link](new ImageIcon("G:\\VoHoaiBao\\hinh\\[Link]"));
panel_2.add(btnNewButton);
JButton btnNewButton_1 = new JButton("M\u1EDBi");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link](null);
textField_1.setText(null);
textField_2.setText(null);
textField_3.setText(null);
[Link]();
}
});
btnNewButton_1.setIcon(new ImageIcon("G:\\VoHoaiBao\\hinh\\[Link]"));
panel_2.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("\u0110\u00F3ng");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link](0);
}
});
btnNewButton_2.setIcon(new ImageIcon("G:\\VoHoaiBao\\hinh\\[Link]"));
panel_2.add(btnNewButton_2);
JPanel panel_3 = new JPanel();
[Link]().add(panel_3);
panel_3.setLayout(new GridLayout(1, 2, 5, 5));
JLabel lblNewLabel_4 = new JLabel("S\u1ED1 l\u1EDBn nh\u1EA5t:");
panel_3.add(lblNewLabel_4);
textField_3 = new JTextField();
textField_3.setBackground(new Color(255, 228, 181));
textField_3.setForeground([Link]);
panel_3.add(textField_3);
textField_3.setColumns(10);
}
}
public class bt3 {
private JFrame frmGiiPhngTrnh;
private JTextField texta;
private JTextField textb;
private JTextField textKQ;
/**
* Launch the application.*/
public static void main(String[] args) {
[Link](new Runnable() {
public void run() {
try {
bt3 window = new bt3();
[Link](true);
} catch (Exception e) {
[Link]();
}
}
});
}
/**
* Create the application.
*/
public bt3() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmGiiPhngTrnh = new JFrame();
[Link]("Gi\u1EA3i Ph\u01B0\u01A1ng Tr\u00ECnh");
[Link](100, 100, 450, 358);
[Link](JFrame.EXIT_ON_CLOSE);
[Link]().setLayout(new
BoxLayout([Link](), BoxLayout.Y_AXIS));
JPanel tieuDe = new JPanel();
[Link]().add(tieuDe);
[Link](new FlowLayout([Link], 5, 5));
JLabel lblNewLabel = new JLabel("GI\u1EA2I PH\u01AF\u01A0NG TR\u00CCNH
B\u1EACC 1");
[Link](new Font("Tahoma", [Link], 20));
[Link](lblNewLabel);
JPanel nhapLieu = new JPanel();
[Link]().add(nhapLieu);
[Link](new GridLayout(2, 2, 0, 15));
JLabel hsa = new JLabel("H\u1EC7 s\u1ED1 a");
[Link](hsa);
texta = new JTextField();
[Link](texta);
[Link](10);
JLabel hsb = new JLabel("H\u1EC7 s\u1ED1 b");
[Link](hsb);
textb = new JTextField();
[Link](textb);
[Link](10);
JPanel tinhToan = new JPanel();
[Link]().add(tinhToan);
[Link](new FlowLayout([Link], 5, 5));
JButton btnNewButton = new JButton("Gi\u1EA3i");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
double hsa = [Link]([Link]());
double hsb = [Link]([Link]());
if (hsa == 0)
{
[Link]("Phương trình vô nghiệm");
}
else
{
[Link]([Link](hsa/hsb));
}
}
});
[Link](new Color(51, 255, 255));
[Link](btnNewButton);
JButton btnNewButton_1 = new JButton("Tho\u00E1t");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link](0);
}
});
btnNewButton_1.setBackground(new Color(51, 255, 51));
[Link](btnNewButton_1);
JButton btnNewButton_2 = new JButton("M\u1EDBi");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link](null);
[Link](null);
[Link](null);
[Link]();
}
});
btnNewButton_2.setBackground(new Color(102, 255, 51));
[Link](btnNewButton_2);
JPanel tongKQ = new JPanel();
[Link]().add(tongKQ);
[Link](new GridLayout(0, 2, 0, 15));
JLabel kQ = new JLabel("K\u1EBFt Qu\u1EA3:");
[Link](kQ);
textKQ = new JTextField();
[Link](new Color(255, 160, 122));
[Link](textKQ);
[Link](10);
}
}
public class bt4 extends JFrame implements ActionListener {
private JTextField txtA, txtB, txtC;
private JButton btnGiai, btnXoaRong, btnThoat;
private JLabel lblKetQua;
public bt4() {
setTitle("Giải phương trình bậc hai");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Tạo các thành phần giao diện
JPanel panel = new JPanel(new FlowLayout([Link], 10, 5)); // Use FlowLayout
for vertical alignment
add(panel, [Link]);
// Labels and TextFields stacked vertically
JLabel lblA = new JLabel("Nhập a:");
[Link](lblA);
txtA = new JTextField(10); // Set preferred column width
[Link](txtA);
JLabel lblB = new JLabel("Nhập b:");
[Link](lblB);
txtB = new JTextField(10);
[Link](txtB);
JLabel lblC = new JLabel("Nhập c:");
[Link](lblC);
txtC = new JTextField(10);
[Link](txtC);
btnGiai = new JButton("Giải");
[Link](this);
[Link](btnGiai);
btnXoaRong = new JButton("Xóa rỗng");
[Link](this);
[Link](btnXoaRong);
btnThoat = new JButton("Thoát");
[Link](this);
[Link](btnThoat);
lblKetQua = new JLabel();
[Link](new Font("Arial", [Link], 16));
[Link](lblKetQua);
// Hiển thị form
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == btnGiai) {
// Lấy giá trị từ các trường nhập dữ liệu
double a = [Link]([Link]());
double b = [Link]([Link]());
double c = [Link]([Link]());
// Giải phương trình bậc hai
double delta = b * b - 4 * a * c;
String ketQua = "";
if (delta > 0) {
// Có hai nghiệm phân biệt
double x1 = (-b + [Link](delta)) / (2 * a);
double x2 = (-b - [Link](delta)) / (2 * a);
ketQua = "x1 = " + x1 + ", x2 = " + x2;
} else if (delta == 0) {
// Có một nghiệm kép
double x = -b / (2 * a);
ketQua = "x = " + x;
} else {
// Vô nghiệm
ketQua = "Vô nghiệm";
}
// Hiển thị kết quả
[Link](ketQua);
} else if ([Link]() == btnXoaRong) {
// Xóa dữ liệu trong các trường nhập dữ liệu
[Link]("");
[Link]("");
[Link]("");
[Link]("");
} else if ([Link]() == btnThoat) {
// Thoát khỏi chương trình
[Link](0);
}
}
public static void main(String[] args) {
new bt4();
}
}
Buổi 3:
public class bt1 {
private JFrame frmngNhp;
private JTextField txtUser;
private JPasswordField txtPass;
/**
* Launch the application.
*/
public static void main(String[] args) {
[Link](new Runnable() {
public void run() {
try {
bt1 window = new bt1();
[Link](true);
} catch (Exception e) {
[Link]();
}
}
});
}
/**
* Create the application.
*/
public bt1() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmngNhp = new JFrame();
[Link]("\u0110\u0103ng Nh\u1EADp");
[Link](100, 100, 450, 300);
[Link](JFrame.EXIT_ON_CLOSE);
[Link]().setLayout(null);
JPanel pnMain = new JPanel();
[Link](0, 0, 10, 10);
[Link]().add(pnMain);
[Link](null);
JLabel lbUser = new JLabel("User Name");
[Link](new Font("Tahoma", [Link], 14));
[Link](32, 26, 84, 14);
[Link]().add(lbUser);
txtUser = new JTextField();
[Link](126, 23, 279, 32);
[Link]().add(txtUser);
[Link](10);
JLabel lbPass = new JLabel("PassWord");
[Link](new Font("Tahoma", [Link], 14));
[Link](32, 72, 84, 14);
[Link]().add(lbPass);
txtPass = new JPasswordField();
[Link](126, 71, 279, 32);
[Link]().add(txtPass);
JPanel pnBtn = new JPanel();
[Link](0, 0, 10, 10);
[Link]().add(pnBtn);
JButton btnLogin = new JButton("Login");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (checkData([Link]() , [Link]() ))
{
[Link](null, "Login success !",
"Login", JOptionPane.INFORMATION_MESSAGE);
}
else
{
[Link](null, "Login failed, try
again", "Login", JOptionPane.ERROR_MESSAGE);
}
}
private boolean checkData(String inputUserName, char[] inputPassword)
{
String username = "VoHoaiBao";
char[] password = {'1','2','3','4'};
return ([Link] (inputPassword,password) &&
[Link](inputUserName));
}
});
[Link](new Color(255, 255, 255));
[Link](164, 132, 72, 23);
[Link]().add(btnLogin);
JButton btnHelp = new JButton("Help");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link](null, "Demo Pass", "Help",
JOptionPane.INFORMATION_MESSAGE);
}
});
[Link](264, 132, 77, 23);
[Link]().add(btnHelp);
}
}
public class bt2 {
private JFrame frmThngTinNgi;
private JTextField txtHt;
private final ButtonGroup buttonGroup = new ButtonGroup();
private final ButtonGroup buttonGroup_1 = new ButtonGroup();
/**
* Launch the application.
*/
public static void main(String[] args) {
[Link](new Runnable() {
public void run() {
try {
bt2 window = new bt2();
[Link]();
[Link](true);
} catch (Exception e) {
[Link]();
}
}
});
}
/**
* Create the application.
*/
public bt2() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmThngTinNgi = new JFrame();
[Link]("Thông tin người dùng");
[Link](100, 100, 450, 423);
[Link](JFrame.EXIT_ON_CLOSE);
JPanel pnMain = new JPanel();
[Link](new EmptyBorder(20, 20, 20, 20));
[Link]().add(pnMain, [Link]);
[Link](null);
JPanel pnThongTin = new JPanel();
[Link](20, 20, 394, 168);
[Link](new TitledBorder(new LineBorder(new Color(0, 0, 255), 2),
"Th\u00F4ng Tin", [Link], [Link], null, new Color(255, 0, 0)));
[Link](pnThongTin);
[Link](null);
JLabel lbHt = new JLabel("Họ Và Tên");
[Link](84, 23, 72, 17);
[Link](new Font("Tahoma", [Link], 14));
[Link](lbHt);
txtHt = new JTextField();
[Link](161, 22, 86, 20);
[Link](txtHt);
[Link](10);
JLabel lnDc = new JLabel("Địa Chỉ");
[Link](84, 64, 48, 17);
[Link](new Font("Tahoma", [Link], 14));
[Link](lnDc);
JTextArea txtDc = new JTextArea();
[Link](161, 62, 86, 20);
[Link](txtDc);
JPanel pnST = new JPanel();
[Link](new TitledBorder(new LineBorder(new Color(255, 0, 0), 2, true), "S\
u1EDF Th\u00EDch", [Link], [Link], null, new Color(255, 0, 0)));
[Link](20, 216, 197, 92);
[Link](pnST);
[Link](null);
JCheckBox ck1 = new JCheckBox("Đi Bơi");
[Link](19, 21, 65, 25);
[Link](new Font("Tahoma", [Link], 14));
[Link](ck1);
JCheckBox ck2 = new JCheckBox("Xem Phim");
[Link](19, 49, 95, 25);
[Link](new Font("Tahoma", [Link], 14));
[Link](ck2);
JPanel pnGT = new JPanel();
[Link](new TitledBorder(new LineBorder(new Color(255, 0, 0), 2, true),
"Gi\u1EDBi T\u00EDnh", [Link], [Link], null, new Color(255, 0, 0)));
[Link](227, 216, 187, 92);
[Link](pnGT);
[Link](null);
JRadioButton ck3 = new JRadioButton("Nam");
buttonGroup_1.add(ck3);
[Link](18, 21, 57, 25);
[Link](new Font("Tahoma", [Link], 14));
[Link](ck3);
JRadioButton ck4 = new JRadioButton("Nữ");
buttonGroup_1.add(ck4);
[Link](18, 49, 47, 25);
[Link](new Font("Tahoma", [Link], 14));
[Link](ck4);
JPanel pnNut = new JPanel();
[Link](184, 319, 214, 27);
[Link](pnNut);
[Link](null);
JButton btnOK = new JButton("OK");
[Link](new ImageIcon("G:\\VoHoaiBao\\hinh\\[Link]"));
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
String hten = [Link]();
String dc = [Link]();
String st = [Link]() ? [Link]() : " ";
String st2 = [Link]() ? [Link]() : " ";
String gt = [Link]() ? "Nam" : "Nữ" ;
[Link](null, "Họ Và Tên: "+ hten + "\nĐịa
Chỉ: " +dc + "\nSở Thich: "+ st + st2 + "\nGiới Tính: "+ gt);
}
});
[Link](10, 0, 89, 23);
[Link](btnOK);
JButton BtnHelp = new JButton("Exit");
[Link](new ImageIcon("G:\\VoHoaiBao\\hinh\\[Link]"));
[Link](109, 0, 99, 23);
[Link](BtnHelp);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link](0);
}
});
}}
public class bt3 {
private JFrame frmTinThng;
private JTextField txtLuong;
/**
* Launch the application.
*/
public static void main(String[] args) {
[Link](new Runnable() {
public void run() {
try {
bt3 window = new bt3();
[Link](true);
} catch (Exception e) {
[Link]();
}
}
});
}
/**
* Create the application.
*/
public bt3() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmTinThng = new JFrame();
[Link]("Tiền Thưởng");
[Link](100, 100, 450, 300);
[Link](JFrame.EXIT_ON_CLOSE);
[Link]().setLayout(null);
JPanel main = new JPanel();
[Link](new EmptyBorder(20, 20, 20, 20));
[Link](0, 0, 434, 262);
[Link]().add(main);
[Link](null);
JLabel lblTnhTinThng = new JLabel("Tính tiền thưởng cuối năm");
[Link](new Color(0, 255, 0));
[Link](new Font("Tahoma", [Link], 26));
[Link]([Link]);
[Link](10, 2, 414, 32);
[Link](lblTnhTinThng);
JPanel pnThongTin = new JPanel();
[Link](new TitledBorder(new LineBorder(new Color(0, 0, 0), 2, true),
"Th\u00F4ng tin thu nh\u1EADp", [Link], [Link], null, new Color(255,
0, 0)));
[Link](10, 45, 414, 109);
[Link](pnThongTin);
[Link](null);
JLabel lbLuong = new JLabel("Tiền lương: ");
[Link](new Font("Tahoma", [Link], 14));
[Link](10, 21, 90, 22);
[Link](lbLuong);
txtLuong = new JTextField();
[Link](106, 25, 285, 20);
[Link](txtLuong);
[Link](10);
JLabel lbXL = new JLabel("Xếp Loại");
[Link](new Font("Tahoma", [Link], 14));
[Link]([Link]);
[Link](-88, 54, 163, 22);
[Link](lbXL);
JComboBox comboBox = new JComboBox();
[Link](106, 57, 100, 20);
[Link](comboBox);
}
}
public class bt3 extends JFrame implements ActionListener {
// Khai báo các thành phần giao diện
private JTextField txtSoThu1, txtSoThu2, txtKetQua;
private JRadioButton radCong, radTru, radNhan, radChia;
private JButton btnThucHien, btnLamMoi, btnThoat;
public bt3() {
// Khởi tạo form
setTitle("Máy Tính Đơn Giản");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Tạo panel chứa các thành phần
JPanel panel = new JPanel(new GridLayout(5, 2, 5, 5));
// Thêm các thành phần vào panel
[Link](new JLabel("Số Thứ 01:"));
txtSoThu1 = new JTextField();
[Link](txtSoThu1);
[Link](new JLabel("Số Thứ 02:"));
txtSoThu2 = new JTextField();
[Link](txtSoThu2);
[Link](new JLabel("Phép Toán:"));
radCong = new JRadioButton("Cộng");
radTru = new JRadioButton("Trừ");
radNhan = new JRadioButton("Nhân");
radChia = new JRadioButton("Chia");
ButtonGroup group = new ButtonGroup();
[Link](radCong);
[Link](radTru);
[Link](radNhan);
[Link](radChia);
[Link](radCong);
[Link](radTru);
[Link](radNhan);
[Link](radChia);
[Link](new JLabel("Kết Quả:"));
txtKetQua = new JTextField();
[Link](false);
[Link](txtKetQua);
// Thêm các nút bấm
btnThucHien = new JButton("Thực Hiện");
[Link](this);
[Link](btnThucHien);
btnLamMoi = new JButton("Làm Mới");
[Link](this);
[Link](btnLamMoi);
btnThoat = new JButton("Thoát");
[Link](this);
[Link](btnThoat);
// Thêm panel vào form
add(panel);
}
// Xử lý sự kiện click nút bấm
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == btnThucHien) {
// Lấy giá trị từ các ô nhập liệu
String soThu1Str = [Link]();
String soThu2Str = [Link]();
String phepToan = "";
if ([Link]()) {
phepToan = "+";
} else if ([Link]()) {
phepToan = "-";
} else if ([Link]()) {
phepToan = "*";
} else if ([Link]()) {
phepToan = "/";
}
// Tính toán kết quả
double soThu1 = [Link](soThu1Str);
double soThu2 = [Link](soThu2Str);
double ketQua = 0;
try {
switch (phepToan) {
case "+":
ketQua = soThu1 + soThu2;
break;
case "-":
ketQua = soThu1 - soThu2;
break;
case "*":
ketQua = soThu1 * soThu2;
break;
case "/":
if (soThu2 == 0) {
throw new ArithmeticException("Chia cho 0");
}
ketQua = soThu1 / soThu2;
break;
}
} catch (NumberFormatException ex) {
[Link](this, "Lỗi: Nhập số không hợp lệ!", "Thông báo",
JOptionPane.ERROR_MESSAGE);
return;
} catch (ArithmeticException ex) {
[Link](this, "Lỗi: " + [Link](), "Thông báo",
JOptionPane.ERROR_MESSAGE);
return;
}
// Hiển thị kết quả
[Link]([Link]("%.2f", ketQua));
} else if ([Link]() == btnLamMoi) {
// Xóa dữ liệu trong các ô nhập liệu
[Link]("");
[Link]("");
[Link]("");
// Chọn lại nút radio mặc định
[Link](true);
} else if ([Link]() == btnThoat) {
// Thoát chương trình
[Link](0);
}
}
public static void main(String[] args) {
// Hiển thị form
new bt3().setVisible(true);
}}
public class bt3 extends JFrame implements ActionListener {
private JTextField txtA, txtB, txtC;
private JLabel lblKetQua;
private JButton btnThucHien, btnLamMoi, btnThoat;
public bt3() {
setTitle("Xét loại tam giác");
setSize(400, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Tạo các widget
JLabel lblA = new JLabel("Cạnh A:");
txtA = new JTextField(10);
JLabel lblB = new JLabel("Cạnh B:");
txtB = new JTextField(10);
JLabel lblC = new JLabel("Cạnh C:");
txtC = new JTextField(10);
btnThucHien = new JButton("Thực hiện");
[Link](this);
btnLamMoi = new JButton("Làm Mới");
[Link](this);
btnThoat = new JButton("Thoát");
[Link](this);
lblKetQua = new JLabel();
// Bố trí các widget
JPanel panel = new JPanel();
[Link](new GridLayout(5, 2, 5, 5));
[Link](lblA);
[Link](txtA);
[Link](lblB);
[Link](txtB);
[Link](lblC);
[Link](txtC);
[Link](btnThucHien);
[Link](btnLamMoi);
[Link](btnThoat);
[Link](lblKetQua);
add(panel);
}
public static void main(String[] args) {
new bt3().setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == btnThucHien) {
// Lấy giá trị từ các ô nhập
double a = [Link]([Link]());
double b = [Link]([Link]());
double c = [Link]([Link]());
// Kiểm tra ba cạnh có hợp thành tam giác hay không
if (!isValidTriangle(a, b, c)) {
[Link]("Ba cạnh A, B và C không hợp thành tam giác !!!");
return;
}
// Xác định loại tam giác
String triangleType = triangleType(a, b, c);
// Hiển thị kết quả
[Link]("Loại tam giác: " + triangleType);
} else if ([Link]() == btnLamMoi) {
// Xóa các giá trị trong các ô nhập
[Link]("");
[Link]("");
[Link]("");
// Hiển thị kết quả rỗng
[Link]("");
} else if ([Link]() == btnThoat) {
// Thoát chương trình
[Link](0);
}
}
// Hàm kiểm tra ba cạnh có hợp thành tam giác hay không
private boolean isValidTriangle(double a, double b, double c) {
return a + b > c && a + c > b && b + c > a;
}
// Hàm xét loại tam giác
private String triangleType(double a, double b, double c) {
if (a == b && b == c) {
return "Tam giác đều";
} else if (a == b || b == c || a == c) {
return "Tam giác cân";
} else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a) {
return "Tam giác vuông";
} else {
return "Tam giác thường";
}
}
}
Buổi 4: Có file riêng
Buổi 5:
public class Bai01 {
private JFrame frame;
private JTextField txtHoTen;
private JTree tree;
public static void main(String[] args) {
[Link](new Runnable() {
public void run() {
try {
Bai01 window = new Bai01();
[Link](true);
} catch (Exception e) {
[Link]();
}
}
});
}
public Bai01() {
initialize();
}
private void initialize() {
frame = new JFrame();
[Link](100, 100, 609, 430);
[Link](JFrame.EXIT_ON_CLOSE);
[Link]().setLayout(null);
JLabel lblNewLabel = new JLabel("THÔNG TIN CÁC NGÀNH HỌC");
[Link](new Font("Tahoma", [Link], 24));
[Link](32, 0, 363, 36);
[Link]().add(lblNewLabel);
JButton btnThem = new JButton("Thêm");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
TreeSelectionModel smd = [Link]();
if ([Link]() > 0) {
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)
[Link]()
.getLastPathComponent();
DefaultMutableTreeNode newNode = new
DefaultMutableTreeNode([Link]());
[Link](newNode);
DefaultTreeModel model = (DefaultTreeModel) [Link]();
[Link]();
for (int i = 0; i < [Link](); i++) {
[Link](i);
}
} else {
[Link](null, "Bạn chưa chọn Node !!!");
}
}
});
[Link](10, 47, 112, 23);
[Link]().add(btnThem);
JButton btnCapNhat = new JButton("Cập Nhật");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
TreeSelectionModel smd = [Link]();
if ([Link]() > 0) {
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)
[Link]()
.getLastPathComponent();
[Link]([Link]());
DefaultTreeModel model = (DefaultTreeModel) [Link]();
[Link]();
for (int i = 0; i < [Link](); i++) {
[Link](i);
}
} else {
[Link](null, "Bạn chưa chọn Node !!!");
}
}
});
[Link](10, 80, 111, 23);
[Link]().add(btnCapNhat);
JButton btnXoa = new JButton("Xoá");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
TreeSelectionModel smd = [Link]();
if ([Link]() > 0) {
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)
[Link]()
.getLastPathComponent();
DefaultTreeModel model = (DefaultTreeModel) [Link]();
if (selectedNode != [Link]().getRoot()) {
[Link](selectedNode);
[Link]();
for (int i = 0; i < [Link](); i++) {
[Link](i);
}
} else {
[Link](null, "Không được Xoá Node root !!!");
}
} else {
[Link](null, "Bạn chưa chọn Node !!!");
}
}
});
[Link](10, 111, 109, 23);
[Link]().add(btnXoa);
JLabel lblNhapTT = new JLabel("Nhập thông tin:");
[Link](10, 147, 100, 14);
[Link]().add(lblNhapTT);
txtHoTen = new JTextField();
[Link](110, 144, 122, 20);
[Link]().add(txtHoTen);
[Link](10);
JPanel pnTree = new JPanel();
[Link](242, 47, 182, 204);
[Link]().add(pnTree);
[Link](new BorderLayout(0, 0));
JScrollPane scrollPane = new JScrollPane();
[Link](scrollPane, [Link]);
tree = new JTree();
[Link](new DefaultTreeModel(new DefaultMutableTreeNode("KCNTT") {
{
DefaultMutableTreeNode node_1;
node_1 = new DefaultMutableTreeNode("Ngành KTPM");
node_1.add(new DefaultMutableTreeNode(""));
node_1.add(new DefaultMutableTreeNode(""));
node_1.add(new DefaultMutableTreeNode(""));
node_1.add(new DefaultMutableTreeNode(""));
add(node_1);
node_1 = new DefaultMutableTreeNode("Ngành TNNT");
node_1.add(new DefaultMutableTreeNode(""));
node_1.add(new DefaultMutableTreeNode(""));
node_1.add(new DefaultMutableTreeNode(""));
node_1.add(new DefaultMutableTreeNode(""));
add(node_1);
node_1 = new DefaultMutableTreeNode("Ngành KHDL");
node_1.add(new DefaultMutableTreeNode(""));
node_1.add(new DefaultMutableTreeNode(""));
node_1.add(new DefaultMutableTreeNode(""));
node_1.add(new DefaultMutableTreeNode(""));
add(node_1);
}
}));
[Link](tree, [Link]);
}
}
public class Bai02 {
private JFrame frame;
private JLabel lbHinh;
/**
* Launch the application. */
public static void main(String[] args) {
[Link](new Runnable() {
public void run() {
try {
Bai02 window = new Bai02();
[Link](true);
} catch (Exception e) {
[Link]();
}
}
});
}
/**
* Create the application.
*/
public Bai02() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
[Link](100, 100, 450, 300);
[Link](JFrame.EXIT_ON_CLOSE);
[Link]().setLayout(null);
JButton btnNewButton = new JButton("\u0110\u00D3NG");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
[Link](147, 11, 89, 23);
[Link]().add(btnNewButton);
JPanel panel = new JPanel();
[Link](0, 50, 434, 212);
[Link]().add(panel);
[Link](null);
lbHinh = new JLabel("");
[Link](0, 11, 434, 207);
[Link](lbHinh);
[Link](new MouseAdapter() {
public void mousePressed(MouseEvent e){
if ([Link](e)){
showImg([Link](),[Link]());
}
}
});
}
private void showImg(int x, int y){
JPopupMenu pop = new JPopupMenu();
[Link]("Nha trang").addActionListener(e ->
showImage("danhSachHinh/[Link]" ));
[Link]("Hoi an").addActionListener(e -> showImage("danhSachHinh/[Link]" ));
[Link]("Phong Nha ke bang").addActionListener(e ->
showImage("danhSachHinh/[Link]" ));
[Link]("sapa").addActionListener(e -> showImage("danhSachHinh/[Link]" ));
[Link](lbHinh, x, y);
}
private void showImage (String path){
ImageIcon icon = new ImageIcon(path);
[Link](icon);
}
}