问题描述
我正在尝试在我的jpanel中激活此gif,但是无论何时我运行该程序,面板都只会显示图像,而不会运动。我已经尝试过使用框架而不是面板来单独进行此操作,并且效果很好(不确定它们是否相关)。重述显示的图像,但将其显示为静止图像而不是“ gif”
更新:我现在可以使用gif了,但是它涵盖了诸如“客户端”,“帮助”和“所有者”之类的按钮,是否有可能使gif一直位于背面并且按钮位于gif的顶部?
-代码
public void panel1() {
ImagePanel panel = new ImagePanel(new ImageIcon("MenuBG.gif").getimage());
firstPanel = new JPanel();
firstPanel.setLayout(null);
client = new JButton("Client");
owner = new JButton("Owner");
client.setSize(90,20);
client.setLocation(xPosAlignLeft,50);
owner.setSize(90,20);
owner.setLocation(xPosAlignLeft,115);
firstPanel.add(client);
firstPanel.add(owner);
createHelpButton();
help.setSize(90,20);
help.setLocation(xPosAlignLeft,180);
firstPanel.add(help);
firstPanel.add(panel);
}
class ImagePanel extends JPanel {
private Image img;
public ImagePanel(String img) {
this(new ImageIcon(img).getimage());
}
public ImagePanel(Image img) {
this.img = img;
Dimension size= new Dimension(img.getWidth(null),img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}
public void paintComponent(Graphics g) {
g.drawImage(img,null);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)