JavaSE series code 37: Add a label object to the window

When Java application is running, it needs to load the bytecode file into memory, so there are special requirements for the location of the bytecode file. There are four main situations:

  1. Use the class without package name in the directory where the current application is located;
  2. Use the classes in the class library in the Java runtime environment;
  3. Use the classes in the descendant directory of the current directory of the application;
  4. Use java to run classes in environment extension.
import java.awt.*; 
public class Javase_37
{
  static Frame frm=new Frame("标签类窗口");
  static Label lab=new Label();    //创建标签对象
  public static void main(String[] args)
  {
    frm.setSize(300,200); 
    frm.setBackground(Color.pink);     //设置窗口底色的粉红色
    lab.setText("我是一个标签");      //设置标签显示的文字
    lab.setAlignment(Label.CENTER);  //将标签内的文字居中
    lab.setBackground(Color.yellow);   //设置标签的底色为黄色
    lab.setForeground(Color.red);      //设置标签上的文字为红色
    Font fnt=new Font("Serief",Font.BOLD+Font.ITALIC,20);
    lab.setFont(fnt);          //设置标签上字体的样式
    frm.add(lab);            //将标签加入到窗口中
    frm.setVisible(true);
  }
}
Published 52 original articles · Like 162 · Visitors 10,000+

Guess you like

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