1
我试图让一个gif出现在我的一个JFrame上,程序编译但没有显示我想要显示的gif。这是我在电脑上存储gif的地方吗?Gif没有显示在JFrame
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class iWorkoutScreen
{
public void iWorkoutScreen()
{
String calories = "this many";
this.setBackground(Color.WHITE);
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(800, 400));
this.pack();
JButton button = new JButton("Press to Start Workout");
this.add(button, BorderLayout.PAGE_START);
JLabel timer = new JLabel("this timer will be better");
timer.setPreferredSize(new Dimension(400, 10));
ImageIcon timerIcon = new ImageIcon("7TaK4G8TA.gif");
timer.setIcon(timerIcon);
this.add(timer, BorderLayout.CENTER);
button = new JButton("Button 3 (LINE_START)");
this.add(button, BorderLayout.LINE_START);
button = new JButton("Long-Named Button 4 (PAGE_END)");
this.add(button, BorderLayout.LINE_END);
JLabel caloriesBurned = new JLabel("You have burned " + calories + " calories!!");
this.add(caloriesBurned, BorderLayout.PAGE_END);
}
}
问题很可能是图像的位置。请做一个搜索。这里每天都会问到一些关于添加图像的问题,并且许多问题是由文件相对于正在使用的路径的位置引起的。请参阅[此处](http://stackoverflow.com/a/9866659/2587435) – 2014-11-07 02:42:11
此外,您应该打包框架_after_添加组件 – 2014-11-07 02:51:53
应用程序资源在部署时将成为嵌入式资源,所以启动像现在一样访问它们。 [tag:embedded-resource]必须通过URL而不是文件访问。请参阅[信息。页面为嵌入式资源](http://stackoverflow.com/tags/embedded-resource/info)如何形成的URL。 – 2014-11-07 04:11:51