- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class Ch0001 {
- JFrame fm;
- JLabel lb[]=new JLabel[6];
- ImageIcon ii[]=new ImageIcon[6];
- ImageIcon icon;
-
- public Ch0001() {
- icon=new ImageIcon(Ch0001.class.getResource("pic/icon.png"));
- for(int i=0; i<6; i++)
- ii[i]=new ImageIcon(Ch0001.class.getResource("pic/0"+(i+1)+".png"));
- for(int i=0; i<6; i++)
- lb[i]=new JLabel(ii[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);
- fm=new JFrame("以陣列方式布置大量元件");
- fm.setBounds(100, 100, 420, 320);
- fm.setVisible(true);
- fm.setResizable(false);
- fm.setLayout(null);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fm.setIconImage(icon.getImage());
- for(int i=0; i<6; i++)
- fm.add(lb[i]);
- }
- public static void main(String[] args) {
- new Ch0001();
- }
- }
複製代碼 |