JavaSE series code 40: Set the text box and text area

  1. Definition of inheritance
    The so-called class inheritance means that the subclass inherits the member variables and methods of the parent class as its own member variables and methods, as if they were declared directly in the subclass. Of course, there are some restrictions on whether the subclass can inherit the variables and methods of the parent class. It is described in detail below.
  2. Inheritance of children and parents in the same package
    If the subclass and the parent are in the same package, the subclass naturally inherits the member variable that is not private in its parent class as its own member variable, and also naturally inherits the method that is not private in its parent class as its own method. Inherited member variables and method access remain unchanged.
import java.awt.*; 
public class Javase_40 extends Frame
{
  TextField tf1=new TextField("该文本框不可编辑",20);
  static TextField tf2=new TextField("口令输入框",20);
  public app12_6(String str)   //构造方法
  {
    super(str);   //调用父类Frame的构造方法
    tf1.setBounds(20,60,120,20);
    tf1.setEditable(false);          //设置文本框对象tf1为不可编辑
    add(tf1);    //将文本框对象tf1加入到窗口中
  }
  public static void main(String[] args)
  {
    Javase_40 frm=new Javase_40("文本编辑功能");  //调用app12_6类构造方法
     TextArea ta=new TextArea ("您好",10,20,TextArea. SCROLLBARS_VERTICAL_ONLY);
    frm.setLocation(200,150);
    frm.setSize(240,220);
    frm.setLayout(null);    //取消页面设置
    tf2.setBounds(20,30,120,20);
    tf2.setEchoChar('*');    //设置文本框对象tf2的回显字符为“*”
    ta.setBounds(20,90,140,100);
    frm.add(tf2);
    frm.add(ta);
    System.out.println(tf2.getText());
    frm.setVisible(true);
  }
}
Published 52 original articles · Like 162 · Visitors 10,000+

Guess you like

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