2020-04-11
19:42:22
GUI:图形用户界面(Graphical User Interface)
今天开始进入了AWT的学习:万事如期而至
进行窗口界面化首先需要一个Frame。
Frame
这个Frame是基本的窗口。
frame中可以添加各种组件。eg:panel、button、TextArea、Label…
首先尝试着做一个小窗口
public class MyFrame extendsFrame {//可能存在多个窗口,我们需要一个计数器
static int id = 0;
MyFrame(){}
MyFrame(String title,Color color ,int x,int y ,int w ,inth){super("MyFrame"+ (id++));
setResizable(false);
setBackground(color);
setBounds(x,y,w,h);
setVisible(true);
}
}
这是封装后的一个小窗口。
上面也是基本的属性设置。
Panel面板
public classTestPanel {public static voidmain(String[] args) {
Frame frame= newFrame();
Panel panel= newPanel();
frame.setLayout(null);
frame.setBounds(300,300,500,500);
frame.setBackground(Color.GREEN);
panel.setBounds(300,300,200,200);
panel.setBackground(Color.RED);
frame.addWindowListener(newWindowAdapter() {
@Overridepublic