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

  4. public class Ch0001 {
  5.         JFrame fm;
  6.         JLabel lb[]=new JLabel[6];
  7.     ImageIcon ii[]=new ImageIcon[6];
  8.     ImageIcon icon;
  9.    
  10.         public Ch0001() {
  11.                 icon=new ImageIcon(Ch0001.class.getResource("pic/icon.png"));
  12.                 for(int i=0; i<6; i++)
  13.                         ii[i]=new ImageIcon(Ch0001.class.getResource("pic/0"+(i+1)+".png"));
  14.                 for(int i=0; i<6; i++)
  15.                         lb[i]=new JLabel(ii[i]);
  16.                 for(int i=0; i<3; i++)
  17.                         lb[i].setBounds(12+i*130, 10, 128, 128);
  18.                 for(int i=3; i<6; i++)
  19.                         lb[i].setBounds(12+(i-3)*130, 150, 128, 128);

  20.                 fm=new JFrame("以陣列方式布置大量元件");
  21.                 fm.setBounds(100, 100, 420, 320);
  22.                 fm.setVisible(true);
  23.                 fm.setResizable(false);
  24.                 fm.setLayout(null);
  25.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26.                 fm.setIconImage(icon.getImage());
  27.                 for(int i=0; i<6; i++)
  28.                         fm.add(lb[i]);   
  29.         }
  30.         public static void main(String[] args) {
  31.                 new Ch0001();
  32.         }

  33. }
複製代碼

TOP

返回列表