Frame类是窗口的意思,是Gui的一个基本,Gui可以用于客户端页面书写(学长传授)。
public static void main(String[] args){
//标题
Frame myFrame = new Frame("Hello World");
//设置可见性
myFrame.setVisible(true);
//设置窗口大小
myFrame.setSize(300, 300);
//设置颜色
myFrame.setBackground(Color.BLUE);
//RGB颜色
myFrame.setBackground(new Color(200,200,200));
//初始位置距离左上角
myFrame.setLocation(200,200);
//窗口大小不可改变
myFrame.setResizable(false);
myFrame.setLayout(null);
//组件
Panel myPanel = new Panel();
//组件颜色
myPanel.setBackground(new Color(0,0,0));
//组件相对于窗口的位置
myPanel.setBounds(10,10,100,100);
//把组件添加到窗口
myFrame.add(myPanel);
myFrame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}