返回列表 發帖
  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.ImageIcon;

  4. public class JPA01 {

  5.         JFrame fm;
  6.         JLabel lb[]=new JLabel[6];
  7.         ImageIcon ii[]=new ImageIcon[6];
  8.         ImageIcon icon;
  9.         
  10.         JPA01()
  11.         {
  12.                 icon=new ImageIcon(JPA01.class.getResource("pic/icon.png"));
  13.                 for(int i=0; i<6; i++)
  14.                         ii[i]=new ImageIcon(JPA01.class.getResource("pic/0"+(i+1)+".png"));
  15.             
  16.             for(int i=0; i<6; i++)
  17.                     lb[i]=new JLabel(ii[i]);
  18.            
  19.             for(int i=0; i<3; i++)
  20.                     lb[i].setBounds(12+i*130, 10, 128, 128);
  21.            
  22.             for(int i=3; i<6; i++)
  23.                     lb[i].setBounds(12+(i-3)*130, 150, 128, 128);
  24.            
  25.             fm=new JFrame("以陣列方式布置大量元件");
  26.             fm.setBounds(100, 100, 420, 320);
  27.             fm.setVisible(true);
  28.             fm.setResizable(false);
  29.             fm.setLayout(null);
  30.             fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31.             fm.setIconImage(icon.getImage());
  32.             for(int i=0; i<6; i++)
  33.                     fm.add(lb[i]);      
  34.         }
  35.         public static void main(String[] args)
  36.         {
  37.                 new JPA01();
  38.         }
  39. }
複製代碼

TOP

返回列表