Frame
import java.awt.*;
public class FrameTest {
public static void main(String[] args) {
Frame f = new Frame("My first frame");
f.setSize(200,200);
f.setBackground(Color.LIGHT_GRAY);
f.setVisible(true);
}
}
Panel 中加入 Frame
import java.awt.*;
public class TestFrameWithPanel {
public static void main(String[] args) {
Frame f = new Frame("my frame");
f.setSize(400,400);
f.setLocation(450,450);
f.setBackground(Color.LIGHT_GRAY);
f.setVisible(true);
Panel panel = new Panel();
panel.setSize(250,250);
panel.setLocation(100,100);
panel.setBackground(Color.PINK);
Button button = new Button("Hi");
button.setSize(60,60);
button.setLocation(20,20);
button.setBackground(Color.ORANGE);
f.setLayout(null);
panel.setLayout(null);
panel.add(button);
f.add(panel);
}
}