如果我使用 Swing 创建了一个 JButton(名为 butOne),并且希望该按钮在单击时向右移动 10 个像素,我是否还有其他选择:
butOne.setLocation(butOne.getX() + 10, butOne.getY())
?
也许类似于 Visual Basic 的 butOne.left -= 10
?仅仅为了改变X坐标和Y坐标而获取X坐标和Y坐标似乎是一种非常不方便的解决方法。谢谢。
最佳答案
It seems a very inconvenient workaround to get the X coordinate and the Y coordinate merely to change one.
认真的吗?每种语言的做法都不同。不要期望这些方法能够一对一映射。
do I have an alternative other than:
您还可以为自己创建一些实用程序类来执行您习惯使用的常见功能:
public class Basic
{
public static void moveLeft(Component component, int offset)
{
component.setLocation(component.getX() - offset, component.getY());
}
}
然后你可以使用:
Basic.moveLeft(button1, 10);
关于java - 向 JButton 的位置添加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33651917/