- import javax.swing.*;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.GridLayout;
- import javax.swing.border.EtchedBorder;
- public class Ch119 {
- JFrame fm;
- Font ft[]=new Font[6];
- JLabel lb[]=new JLabel[6];
- Ch119()
- {
- ft[0]=new Font("標楷體",Font.BOLD,50);
- ft[1]=new Font("微軟正黑體",Font.BOLD+Font.ITALIC,40);
- ft[2]=new Font("新細明體",Font.ITALIC,60);
- ft[3]=new Font("Times New Roman",Font.PLAIN,60);
- ft[4]=new Font("Arial",Font.ITALIC,40);
- ft[5]=new Font("Manorly",Font.PLAIN,80);
- for(int i=0;i<6;i++)
- {
- if(i<3)
- lb[i]=new JLabel("你好",JLabel.CENTER);
- else
- lb[i]=new JLabel("Hello",JLabel.CENTER);
- lb[i].setBorder(new EtchedBorder());
- lb[i].setFont(ft[i]);
- }
- lb[0].setForeground(Color.BLUE);
- lb[2].setForeground(Color.RED);
- lb[4].setForeground(Color.GRAY);
- fm=new JFrame("Font 類別");
- fm.setBounds(100, 100, 450, 300);
- fm.setVisible(true);
- fm.setResizable(true);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fm.setLayout(new GridLayout(2,3));
- for(int i=0;i<6;i++)
- {
- fm.add(lb[i]);
- }
- }
- public static void main(String[] args) {
- new Ch119();
- }
- }
複製代碼 |