返回列表 發帖
  1. import javax.swing.*;
  2. public class Ch01{
  3.         JFrame fm;
  4.     JLabel lb[]=new JLabel[6];   
  5.     ImageIcon icon,im[]=new ImageIcon[6];
  6.         Ch01()
  7.         {   
  8.                 for(int i=0; i<6; i++)
  9.                         im[i]=new ImageIcon(Ch01.class.getResource("jpg/0"+(i+1)+".png"));
  10.             for(int i=0; i<6; i++)
  11.                     lb[i]=new JLabel(im[i]);
  12.             for(int i=0; i<3; i++)
  13.                     lb[i].setBounds(12+i*130, 10, 128, 128);
  14.             for(int i=3; i<6; i++)
  15.             lb[i].setBounds(12+(i-3)*130, 150, 128, 128);
  16.             icon=new ImageIcon(Ch01.class.getResource("jpg/icon.png"));
  17.                 fm=new JFrame("ImageIcon 類別");
  18.                 fm.setBounds(100, 100, 405, 358);
  19.                 fm.setIconImage(icon.getImage());
  20.                 fm.setVisible(true);
  21.                 fm.setResizable(false);
  22.                 fm.setLayout(null);
  23.                 for(int i=0; i<6; i++)
  24.                 fm.add(lb[i]);
  25.             fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26.             
  27.           
  28.         }

  29.         public static void main(String[] args) {
  30.                 Ch01 a=new Ch01();
  31.         }


  32. }
複製代碼

TOP

返回列表