Code
Code
// Panel Button
JPanel pnNutLenh = new JPanel();
pnNutLenh.setLayout(new FlowLayout());
frm.add(pnTieuDe);
frm.add(pnNhapLieu);
frm.add(pnNutLenh);
frm.setVisible(true);
}}
Buổi 2:
textField_3.setText(String.valueOf(max));
}
});
btnNewButton.setIcon(new ImageIcon("G:\\VoHoaiBao\\hinh\\tk.jpg"));
panel_2.add(btnNewButton);
textField.requestFocus();
}
});
btnNewButton_1.setIcon(new ImageIcon("G:\\VoHoaiBao\\hinh\\load.jpg"));
panel_2.add(btnNewButton_1);
}
public class bt3 {
private JFrame frmGiiPhngTrnh;
private JTextField texta;
private JTextField textb;
private JTextField textKQ;
/**
* Launch the application.*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
bt3 window = new bt3();
window.frmGiiPhngTrnh.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public bt3() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmGiiPhngTrnh = new JFrame();
frmGiiPhngTrnh.setTitle("Gi\u1EA3i Ph\u01B0\u01A1ng Tr\u00ECnh");
frmGiiPhngTrnh.setBounds(100, 100, 450, 358);
frmGiiPhngTrnh.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmGiiPhngTrnh.getContentPane().setLayout(new
BoxLayout(frmGiiPhngTrnh.getContentPane(), BoxLayout.Y_AXIS));
if (delta > 0) {
// Có hai nghiệm phân biệt
double x1 = (-b + Math.sqrt(delta)) / (2 * a);
double x2 = (-b - Math.sqrt(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ả
lblKetQua.setText(ketQua);
} else if (e.getSource() == btnXoaRong) {
// Xóa dữ liệu trong các trường nhập dữ liệu
txtA.setText("");
txtB.setText("");
txtC.setText("");
lblKetQua.setText("");
} else if (e.getSource() == btnThoat) {
// Thoát khỏi chương trình
System.exit(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) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
bt1 window = new bt1();
window.frmngNhp.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public bt1() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmngNhp = new JFrame();
frmngNhp.setTitle("\u0110\u0103ng Nh\u1EADp");
frmngNhp.setBounds(100, 100, 450, 300);
frmngNhp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmngNhp.getContentPane().setLayout(null);
panel.add(lblA);
panel.add(txtA);
panel.add(lblB);
panel.add(txtB);
panel.add(lblC);
panel.add(txtC);
panel.add(btnThucHien);
panel.add(btnLamMoi);
panel.add(btnThoat);
panel.add(lblKetQua);
add(panel);
}
public static void main(String[] args) {
new bt3().setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnThucHien) {
// Lấy giá trị từ các ô nhập
double a = Double.parseDouble(txtA.getText());
double b = Double.parseDouble(txtB.getText());
double c = Double.parseDouble(txtC.getText());
// Kiểm tra ba cạnh có hợp thành tam giác hay không
if (!isValidTriangle(a, b, c)) {
lblKetQua.setText("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ả
lblKetQua.setText("Loại tam giác: " + triangleType);
} else if (e.getSource() == btnLamMoi) {
// Xóa các giá trị trong các ô nhập
txtA.setText("");
txtB.setText("");
txtC.setText("");
// Hiển thị kết quả rỗng
lblKetQua.setText("");
} else if (e.getSource() == btnThoat) {
// Thoát chương trình
System.exit(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) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Bai01 window = new Bai01();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Bai01() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 609, 430);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);