GUI小练习(狂神说Java的小作业)
弄一个跟↓类似的表格!!!
动起小手燥起来
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Demo05 {
public static void main(String[] args) {
Frame frame = new Frame("操作");
Panel panel1 = new Panel();
Panel panel2 = new Panel();
Button b0 =new Button("b0");
Button b1 =new Button("b1");
Button b2 =new Button("b2");
Button b3 =new Button("b3");
Button b4 =new Button("b4");
Button b5 =new Button("b5");
Button b6 =new Button("b6");
Button b7 =new Button("b7");
Button b8 =new Button("b8");
Button b9 =new Button("b9");
frame.setBounds(500,500,500,500);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setLayout(new GridLayout(2,1));
frame.add(panel1);
frame.add(panel2);
panel1.setLayout(new BorderLayout());
panel1.add(b0, BorderLayout.WEST);
panel1.add(b1, BorderLayout.EAST);
Panel p = new Panel();
panel1.add(p,BorderLayout.CENTER);
p.setLayout(new GridLayout(2,1));
p.add(b2);
p.add(b3);
panel2.setLayout(new BorderLayout());
panel2.add(b4,BorderLayout.WEST);
panel2.add(b5,BorderLayout.EAST);
Panel p1 = new Panel();
panel2.add(p1,BorderLayout.CENTER);
p1.setLayout(new GridLayout(2,2));
p1.add(b6);
p1.add(b7);
p1.add(b8);
p1.add(b9);
//代码自己敲得,可能不是那么特别牛畅,请谅解
}
}
//代码自己敲得,可能不是那么特别牛畅,请谅解