- import javax.swing.*;
- public class Ch01{
- JFrame fm;
- JLabel lb[]=new JLabel[6];
- ImageIcon icon,im[]=new ImageIcon[6];
- Ch01()
- {
- for(int i=0; i<6; i++)
- im[i]=new ImageIcon(Ch01.class.getResource("jpg/0"+(i+1)+".png"));
- for(int i=0; i<6; i++)
- lb[i]=new JLabel(im[i]);
- for(int i=0; i<3; i++)
- lb[i].setBounds(12+i*130, 10, 128, 128);
- for(int i=3; i<6; i++)
- lb[i].setBounds(12+(i-3)*130, 150, 128, 128);
- icon=new ImageIcon(Ch01.class.getResource("jpg/icon.png"));
- fm=new JFrame("ImageIcon 類別");
- fm.setBounds(100, 100, 405, 358);
- fm.setIconImage(icon.getImage());
- fm.setVisible(true);
- fm.setResizable(false);
- fm.setLayout(null);
- for(int i=0; i<6; i++)
- fm.add(lb[i]);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
-
- }
- public static void main(String[] args) {
- Ch01 a=new Ch01();
- }
- }
複製代碼 |