1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public class Principal extends Frame {
private static final long serialVersionUID = 8390849717731066438L;
private JButton b1 = null;
private JButton b2 = null;
public Principal()
{
init();
}
public void init()
{
b1 = new JButton();
b1.setText("1");
b1.setBounds(0, 0, 100, 100);
b2 = new JButton();
b2.setText("2");
b2.setBounds(80, 80, 50, 50);
add(b2);
add(b1);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setLayout(null);
setBounds(200, 200, 200, 200);
setVisible(true);
}
public static void main(String[] args) {
new Principal();
}
} |