Java 如何沿X轴移动JFrame?

Java 如何沿X轴移动JFrame?,java,swing,Java,Swing,我是一个相对较新的程序员,所以请容忍我。我用游戏主角的形象创建了一个JFrame。但我不知道如何移动它(通过向x轴添加值,如x++或x-)。有什么办法可以这样做吗 添加字符: final JLabel carl = new JLabel(""); carl.setIcon(new ImageIcon(gui.class.getResource("/main/carl.png"))); carl.setBounds(12, 90, 64, 69); levelOne

我是一个相对较新的程序员,所以请容忍我。我用游戏主角的形象创建了一个JFrame。但我不知道如何移动它(通过向x轴添加值,如x++或x-)。有什么办法可以这样做吗

添加字符:

    final JLabel carl = new JLabel("");
    carl.setIcon(new ImageIcon(gui.class.getResource("/main/carl.png")));
    carl.setBounds(12, 90, 64, 69);
    levelOne.add(carl);
在单击按钮时移动角色(我现在已将其设置为移动到指定坐标):


提前谢谢。

我试过了,但出错了。“类型矩形中的方法setLocation(int,int)不适用于参数(double,double)”有什么建议吗?更新:我稍微修改了您的代码,它工作得很好。非常感谢你帮助我学习这个概念!
    public void actionPerformed(ActionEvent arg0) {
        Rectangle bounds = carl.getBounds(null);
        bounds.setLocation(bounds.getX() + 1, bounds.getY());
        carl.setBounds(bounds);
    }
    public void actionPerformed(ActionEvent arg0) {
        Rectangle bounds = carl.getBounds(null);
        bounds.setLocation(bounds.getX() + 1, bounds.getY());
        carl.setBounds(bounds);
    }