- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class Ch01{
- private JFrame fm;
- JLabel lb[]=new JLabel[6];
- ImageIcon Icon[]=new ImageIcon[6];
- ImageIcon ii;
- Ch01(){
-
- for(int i=0;i<=5;i++){
- Icon[i]=new ImageIcon(Ch01.class.getResource("pic/0"+(i+1)+".png"));
- }
- for(int i=0;i<=5;i++){
- lb[i]=new JLabel(Icon[i]);
- }
- for(int i=0;i<=5;i++){
- lb[i].setBounds(12+(i%3)*130, 10+(i/3)*140, 128, 128);
- }
- ii=new ImageIcon(Ch01.class.getResource("pic/icon.png"));
- fm=new JFrame("布置大量元件");
- fm.setIconImage(ii.getImage());
- fm.setBounds(100, 100, 420, 320);
- fm.setVisible(true);
- fm.setResizable(false);
- fm.setLayout(null);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- for(int i=0;i<=5;i++){
- fm.add(lb[i]);
- }
- }
- public static void main(String[] args) {
- new Ch01();
- }
- }
複製代碼 |