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

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

  31.         }

  32. }
複製代碼
hahahahahahahaha

TOP

返回列表