JavaSE series code 36: load all classes in java.awt class library

The meanings of private, public, protected modifiers are also suitable for construction methods. If a class does not explicitly declare a constructor, the default constructor of the public class is public, and the default constructor of the friendly class is friendly. It should be noted that if there is no public constructor in a public class definition declaration, the constructor used in another class is not public, and the creation of objects is limited.

import java.awt.*;   //加载java.awt类库里的所有类
public class Javase_35
{
  public static void main(String[] args)
  {
    Frame frm=new Frame("我的框架");
    frm.setSize(300,200); 
    frm.setLocation(500,400); 
    frm.setBackground(Color.lightGray); 
    Panel pan=new Panel();
    pan.setSize(150,100); 
    pan.setLocation(50,50); 
    pan.setBackground(Color.green); 
    Button bun=new Button("点击我");
    bun.setSize(80,20); 
    bun.setLocation(50,50); 
    bun.setBackground(Color.yellow); 
    frm.setLayout(null);     //取消frm的默认布局管理器
    pan.setLayout(null);     //取消pan的默认布局管理器
    pan.add(bun);          //将命令按钮加入到面板中
    frm.add(pan);          //将面板加入到窗口中
    frm.setVisible(true);
  }
}
Published 52 original articles · Like 162 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/blog_programb/article/details/105393869