【发布时间】:2013-09-23 03:34:33
【问题描述】:
我有一个paneel.java 文件,代码如下:
import java.awt.*;
import javax.swing.*;
public class Paneel extends JFrame
{
public static void main ( String [] args )
{
// frame
JFrame frame = new Paneel();
frame.setSize ( 1000, 1000 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setTitle( "Remembory" );
frame.setVisible( true );
}
class Gifpaneel extends JPanel{
private ImageIcon gif, animatedGif;
public Gifpaneel() {
gif = new ImageIcon( "test.gif" );
animatedGif = new ImageIcon( "animaties/test.gif" );
}
public void paintComponent( Graphics g ){
super.paintComponent( g );
gif.paintIcon( this, g, 100, 100 );
animatedGif.paintIcon ( this, g, 250, 100 );
}
}
}
我想展示 test.gif 文件。 我该怎么做?因为当我在 eclipse 中运行它时,我只得到没有图像的 jframe。
【问题讨论】:
-
您尚未添加创建 Gifpaneel 对象并将其添加到您的 JFrame。
-
我该如何完成这项工作?
-
请查看如何add images to Eclipse Project,以及此answer 了解更多信息。希望它有所帮助:-)
标签: java image swing gif paintcomponent