Advertisement
KuoHsiangYu

AWTGUI1

Sep 8th, 2019
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. //http://blog.sina.com.cn/s/blog_025270e90101b1db.html
  2. //https://bbs.csdn.net/topics/380242077
  3. package com.sample;
  4.  
  5. import java.awt.Color;
  6. import java.awt.Font;
  7. import java.awt.Frame;
  8. import java.awt.Label;
  9. import java.awt.event.WindowAdapter;
  10. import java.awt.event.WindowEvent;
  11.  
  12. /**
  13.  *
  14.  * @author Hsiang-Yu Kuo
  15.  */
  16. public class AWTGUI1 {
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) {
  21.         // -Dfile.encoding=GB18030
  22.         Frame frame = new Frame("標題 Frame");
  23.         Label label = new Label();// 建立標籤物件label
  24.         frame.setSize(400, 300);
  25.         frame.setLocation(400, 400);// 設定視窗位置      
  26.         frame.setBackground(Color.white);
  27.         // label.setText("中文字 label");// 在標籤內加上文字
  28.         // label.setText(new String("中文字 label".getBytes("UTF-8"), "big5"));//在標籤內加上文字
  29.         label.setText("中文字 简体字 label");// 在標籤內加上文字
  30.         // label.setBackground(Color.white);//設定標籤底色為白色
  31.         label.setBackground(new Color(255, 255, 255));// 設定標籤底色為白色
  32.         label.setAlignment(Label.CENTER);// 將標籤內的文字置中
  33.         label.setForeground(Color.black);// 設定標籤文字
  34.         // Font font = new Font("DialogInput", Font.ITALIC + Font.BOLD, 18);
  35.         Font font = new Font("DialogInput", Font.PLAIN, 28);
  36.         // Font font = new Font("標楷體", Font.PLAIN, 24);
  37.         // Font font = new Font("Consolas", Font.PLAIN, 18);
  38.         label.setFont(font);// 設定字型的樣式
  39.         frame.add(label);
  40.         frame.addWindowListener(new WindowAdapter() {
  41.             @Override
  42.             public void windowClosing(WindowEvent e) {
  43.                 System.exit(0);
  44.             }
  45.         });
  46.         frame.setVisible(true);
  47.     }// end of main method
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement