[r]
(1)package AAA;
import java.awt.Button; import java.awt.Checkbox; import java.awt.CheckboxGroup; import java.awt.Frame;
import java.awt.Label;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;
public class BoGaCa extends Frame /*implements ActionListener*/{
// ActionListener lắng nghe kiện dành cho button Thoát Label labelConVat = new Label("Chon vat:");
CheckboxGroup g = new CheckboxGroup(); Checkbox radioBo = new Checkbox("Bo",g,true); Checkbox radioGa = new Checkbox("Ga",g,false); Checkbox radioCa = new Checkbox("Ca",g,false); Button buttonThoat = new Button("Thoat");
public BoGaCa() {
this.setTitle("Bò Gà Cá"); this.setLayout(null);
(2)radioBo.setBounds(50,80,50,30); radioGa.setBounds(50,120,50,30); radioCa.setBounds(50,160,50,30); this.add(radioBo);
this.add(radioGa); this.add(radioCa);
buttonThoat.setBounds(220,100,100,30); buttonThoat.addActionListener(this); this.add(buttonThoat);
this.addWindowListener(new WindowAdapter() { @Override
public void windowClosing(WindowEvent e) { System.exit(0);
} }); }
public static void main(String[] args) { BoGaCa f = new BoGaCa();
f.setBounds(100,100,350,400); f.setVisible(true);
}
/* @Override
public void actionPerformed(ActionEvent e) { //xử lý kiện cho button Thoát if(e.getSource()== buttonThoat)
(3)System.exit(0); }