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

  4. public class Ch01{
  5.         private JFrame fm;
  6.         JLabel lb[]=new JLabel[6];
  7.         ImageIcon Icon[]=new ImageIcon[6];
  8.         ImageIcon ii;

  9.         Ch01(){
  10.                
  11.                 for(int i=0;i<=5;i++){
  12.                         Icon[i]=new ImageIcon(Ch01.class.getResource("pic/0"+(i+1)+".png"));
  13.                 }
  14.                 for(int i=0;i<=5;i++){
  15.                         lb[i]=new JLabel(Icon[i]);
  16.                 }
  17.                 for(int i=0;i<=5;i++){
  18.                         lb[i].setBounds(12+(i%3)*130, 10+(i/3)*140, 128, 128);
  19.                 }
  20.                 ii=new ImageIcon(Ch01.class.getResource("pic/icon.png"));
  21.         fm=new JFrame("布置大量元件");
  22.                 fm.setIconImage(ii.getImage());
  23.                 fm.setBounds(100, 100, 420, 320);
  24.                 fm.setVisible(true);
  25.                 fm.setResizable(false);
  26.                 fm.setLayout(null);
  27.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28.                 for(int i=0;i<=5;i++){
  29.                         fm.add(lb[i]);
  30.                 }


  31.         }

  32.         public static void main(String[] args) {
  33.                 new Ch01();

  34.         }


  35. }
複製代碼

TOP

返回列表