返回列表 發帖

ImageIcon 類別 (四)

試以陣列方式布置大量元件.

JFrame 的設定: 100, 100, 420, 320
JLabel 的設定:
12, 10, 128, 128
142, 10, 128, 128
272, 10, 128, 128
12, 150, 128, 128
142, 150, 128, 128
272, 150, 128, 128



素材:pic.zip
  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.ImageIcon;

  4. public class Ch87 {

  5.         JFrame fm;
  6.         JLabel lb[]=new JLabel[6];
  7.         ImageIcon ii[]=new ImageIcon[6];
  8.         ImageIcon icon;
  9.        
  10.         Ch87()
  11.         {
  12.                 icon=new ImageIcon(Ch87.class.getResource("pic/icon.png"));
  13.                 for(int i=0; i<6; i++)
  14.                         ii[i]=new ImageIcon(Ch87.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.        
  36.         public static void main(String[] args) {
  37.                 new Ch87();
  38.         }
  39. }
複製代碼

  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

  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

  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

  1. import javax.swing.ImageIcon;
  2. import javax.swing.JFrame;
  3. import javax.swing.JLabel;

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

TOP

  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.       
  10.         Ch01()
  11.         {
  12.                 icon=new ImageIcon(Ch01.class.getResource("pic/icon.png"));
  13.                 for(int i=0; i<6; i++)
  14.                         ii[i]=new ImageIcon(Ch01.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.       
  36.         public static void main(String[] args) {
  37.                 new Ch01();
  38.         }
  39. }
複製代碼

TOP

  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

  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

返回列表