java - Gif 在 jpanel GUI 的背景中没有“移动”并覆盖 jbuttons
问题描述
我试图让这个 gif 在我的 jpanel 中处于活动状态,但是每当我运行程序时,面板只显示图像而不是运动。我曾在一个单独的场合使用框架而不是面板尝试过这个,它有效(不确定它们是否相关)。回顾图像显示,但作为静止图像而不是“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,0,0,null);
}
}
解决方案
推荐阅读
- python - Flask-socketio(服务器端)未收到事件
- javascript - 让我登录 geckodriver selenium (java)
- reactjs - 使用 reactstratp 库自动隐藏 Toast 消息
- python - 为什么我的递归在 Swift 中有效,但在 Python 中无效?
- swift - 使用 DiskArbitration 和 IOKit 获取所有卷的树状结构
- android - 如何在 Android 11 上获取请求所有文件访问权限
- python - 3D t-sne 的特定标记
- node.js - 推送被拒绝,在 heroku 上部署 nodejs 应用程序时无法编译 Node.js 应用程序
- netsuite - 以编程方式安排地图缩减脚本
- python - Pygame 窗口不会出现在 Jupyter 中