JAVA-图片展示

image

package com.itheima;

import javax.swing.*;

public class shuzu08 {
    public static void main(String[] args) {
        //创建窗体对象
        JFrame jf=new JFrame();
        jf.setTitle("图片展示");
        jf.setSize(380, 400);
        jf.setDefaultCloseOperation(3);
        jf.setLocationRelativeTo(null);
        jf.setAlwaysOnTop(true);
        jf.setLayout(null);



        int[][] arr ={
                {1,2,3,4},
                {5,6,7,8},
                {9,10,11,12},
                {13,14,15,16}};

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                //arr[i][j]
                JLabel jLabel= new JLabel(new ImageIcon("images\\"+arr[i][j]+".png"));
                jLabel.setBounds(j*90,i*90, 90,90);
                jf.add(jLabel);
            }
        }
        jf.setVisible(true);
    }
}

posted @ 2022-10-29 15:04  NiceTwocu  阅读(41)  评论(0编辑  收藏  举报