java怎么在JFrame中显示动态图片?
试了一下,从网上找了个GIF
可以用啊
--------------------------------------------------------------------------------------------
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ImageApp extends JFrame {
public ImageApp() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(400, 300);
setResizable(false);
getContentPane().setLayout(null);
JPanel panel = new ImagePanel();
panel.setBounds(0, 0, 400, 300);
getContentPane().add(panel);
setVisible(true);
}
public static void main(String[] args) {
new ImageApp();
}
class ImagePanel extends JPanel {
public void paint(Graphics g) {
super.paint(g);
// ImageIcon icon = new ImageIcon("D:\\1.jpg");
ImageIcon icon = new ImageIcon("D:\\14405937jqhjsppeninjf9.gif");
g.drawImage(icon.getImage(), 0, 0, 400, 300, this);
}
}
}
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ImageApp extends JFrame {
public ImageApp() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(400, 300);
setResizable(false);
getContentPane().setLayout(null);
JPanel panel = new ImagePanel();
panel.setBounds(0, 0, 400, 300);
getContentPane().add(panel);
setVisible(true);
}
public static void main(String[] args) {
new ImageApp();
}
class ImagePanel extends JPanel {
public void paint(Graphics g) {
super.paint(g);
// ImageIcon icon = new ImageIcon("D:\\1.jpg");
ImageIcon icon = new ImageIcon("D:\\14405937jqhjsppeninjf9.gif");
g.drawImage(icon.getImage(), 0, 0, 400, 300, this);
}
}
}
= = 麻烦给段代码看看