java问题 :为什麽gif文件无法显示出来?

来源:百度知道 编辑:UC知道 时间:2024/05/05 10:11:31
public class Exercises12_7 extends JFrame{
private ImageIcon icon1=new ImageIcon("image/1.gif");
private ImageIcon icon2=new ImageIcon("image/2.gif");

public Exercises12_7() {
setLayout(new GridLayout(2,3,5,5));
JLabel jlb1=new JLabel(icon1);
JLabel jlb2=new JLabel(icon2);
add(jlb1);
add(jlb2);
}

public static void main(String[] args) {
Exercises12_7 frame=new Exercises12_7();
frame.setSize(500,300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Exercises12.7:");
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;

能显示。。我试过了,肯定是你的路径问题。程序本身没问题
private ImageIcon icon1=new ImageIcon("image/1.gif");
修改这一句,看是否有这张图片,路径是否正确