JavaSE Series Code 39: Set Command Button

Subclass and superclass
Inheritance is a mechanism for creating new classes from existing classes. With inheritance, we can first create a general class with common attributes, and then create a new class with special attributes according to the general class. The new class inherits the state and behavior of the general class, and adds its own new state and behavior as needed. The class derived from inheritance is called subclass, and the inherited class is called superclass.

import java.awt.*; 
public class Javase_39 extends Frame  //指定app12_5继承自Frame类
{
  public static void main(String[] args)
  {
    app12_5 frm=new app12_5();  //用app12_5类产生frm对象
    Button btn=new Button("确定");    //创建按钮对象
    frm.setLayout(null);    //取消页面设置
    frm.setSize(300,200);
    frm.setTitle("按钮类窗口");
    btn.setBounds(50,70,100,40);   //设置按钮的大小与位置
    frm.add(btn); 
    frm.setVisible(true);
  }
}
Published 52 original articles · Like 162 · Visitors 10,000+

Guess you like

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