JavaSE series code 42: Use of FlowLayout class

Inheritance related polymorphism means that when a method of a parent class is rewritten by its subclass, it can produce its own functional behavior, that is, different behaviors may occur when the same operation is called by different types of objects. For example, both dogs and cats have the function of mammals: “barking”. When dogs operate “barking”, the sound produced is “barking” , and when the cat operates the “meow”, the voice is “meow”, which is the “meow” polymorphism.
When a class has many subclasses, and these subclasses all override a method in the parent class. When we put the reference of the object created by a subclass into the object of a parent class, we get an upper transformation object of the object. Then the upper transformation object may have multiple forms when calling this method.

import java.awt.*; 
public class Javase_42 extends Frame
{
  static Frame frm=new Frame("流式布局设置管理器FlowLayout");
  public static void main(String[] args)
  {
    FlowLayout flow=new FlowLayout (FlowLayout.CENTER,5,10);
    Button but=new Button("按钮");
    Label lab=new Label("我是一个标签");
    frm.setLayout(flow);      //设置页面布局为流式布局方式
    frm.setSize(200,150);
    frm.setBackground(Color.PINK);     //设置窗口背景为粉红色
    frm.add(but);      //添加命令按钮组件
    frm.add(lab);      //添加标签组件
    frm.add(new TextField("流式布局策略FlowLayout",18)); //添加文本框组件
    frm.setVisible(true);
  }
}
Published 52 original articles · Like 162 · Visitors 10,000+

Guess you like

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