返回列表 發帖
  1. import javax.swing.*;
  2. import java.awt.GridLayout;
  3. import javax.swing.border.EtchedBorder;
  4. import javax.swing.border.TitledBorder;
  5. public class Ch117 {
  6.         JFrame fm;
  7.         JButton btn[]=new JButton[4];
  8.         JPanel pn1,pn2,pn3;
  9.         Ch117()
  10.         {
  11.             for(int i=0; i<4; i++)
  12.                 btn[i]=new JButton("按鈕"+(i+1));              
  13.             pn1=new JPanel();
  14.             pn1.setBorder(new EtchedBorder());
  15.             pn2=new JPanel();
  16.             pn2.setBorder(new TitledBorder("第二區"));
  17.             pn3=new JPanel();
  18.             pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
  19.             pn3.setLayout(new GridLayout(4,1,5,5));
  20.             for(int i=0; i<4; i++)
  21.                 pn3.add(btn[i]);
  22.             fm=new JFrame("JPanel & setBorder()");
  23.             fm.setBounds(100, 100, 450, 300);
  24.             fm.setVisible(true);
  25.             fm.setResizable(true);
  26.             fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27.             fm.setLayout(new GridLayout());
  28.             fm.add(pn1);
  29.             fm.add(pn2);
  30.             fm.add(pn3);
  31.         }
  32.         public static void main(String[] args) {
  33.             new Ch117();
  34.         }
  35. }
複製代碼

TOP

  1. import javax.swing.*;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.GridLayout;
  5. import javax.swing.border.EtchedBorder;
  6. public class Ch119 {
  7.         JFrame fm;
  8.         Font ft[]=new Font[6];
  9.         JLabel lb[]=new JLabel[6];
  10.         Ch119()
  11.         {   
  12.             ft[0]=new Font("標楷體",Font.BOLD,50);
  13.             ft[1]=new Font("微軟正黑體",Font.BOLD+Font.ITALIC,40);
  14.             ft[2]=new Font("新細明體",Font.ITALIC,60);
  15.             ft[3]=new Font("Times New Roman",Font.PLAIN,60);
  16.             ft[4]=new Font("Arial",Font.ITALIC,40);
  17.             ft[5]=new Font("Manorly",Font.PLAIN,80);
  18.                 for(int i=0;i<6;i++)
  19.             {
  20.                     if(i<3)
  21.                             lb[i]=new JLabel("你好",JLabel.CENTER);
  22.                     else
  23.                             lb[i]=new JLabel("Hello",JLabel.CENTER);
  24.                     lb[i].setBorder(new EtchedBorder());
  25.                     lb[i].setFont(ft[i]);
  26.             }
  27.                 lb[0].setForeground(Color.BLUE);
  28.                 lb[2].setForeground(Color.RED);
  29.                 lb[4].setForeground(Color.GRAY);
  30.                 fm=new JFrame("Font 類別");
  31.             fm.setBounds(100, 100, 450, 300);
  32.             fm.setVisible(true);
  33.             fm.setResizable(true);
  34.             fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  35.             fm.setLayout(new GridLayout(2,3));
  36.             for(int i=0;i<6;i++)
  37.             {
  38.                     fm.add(lb[i]);
  39.             }
  40.         }
  41.         public static void main(String[] args) {
  42.             new Ch119();
  43.         }
  44. }
複製代碼

TOP

返回列表