具有绝对定位的 JLabel ImageIcon 示例

ImageIcon by JLabel example with absolute positioning

我看过很多示例代码,但 none 专门向我展示了如何在不使用布局管理器的情况下通过在 JFrame 上使用 JLabel 来显示 ImageIcon。我一再被告知绝对定位比布局管理器麻烦且效率低,但我更喜欢完全控制我的元素的去向。将在具有绝对定位的 JFrame 上显示图像的 JLabel 的完整示例 class(没有添加额外的东西)非常感谢,谢谢

The image I need has to move around the screen

原始问题中缺少一条重要信息。我对此使用空布局没有问题。

I wanted to move around with arrow keys on the screen?

不要为此使用 KeyListener。相反,您应该使用键绑定。

请参阅 Motion Using the Keyboard 中的 KeyboardAnimation.java 代码以获取此问题的一种解决方案。