是否可以使用坐标定位 JButton?

Is it possible to position a JButton using coordinates?

我一直在尝试定位 JButton,但遇到了很多麻烦。我需要他们去一个非常精确的位置,但不知道如何实现。我见过一个叫做 FlowLayout 的东西,但我对它很困惑。几天前我问了另一个关于如何定位 JButton 的问题,他们给了我这个固定代码:

import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Frame extends JFrame
{
private JButton button1;
private JButton button2;

public Frame()
{
    button1 = new JButton("Hello button1");
    button2 = new JButton("Hello button2");
    button2.setPreferredSize(new Dimension(100,100));
    button1.setPreferredSize(new Dimension(100,100));
    add(button2);
    add(button1);
}

}

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Panel extends JPanel
{
public static void main(String args [])
{
    Frame frame = new Frame();
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setVisible(true);
}
}

首先,不要在从左到右的流中使用 FlowLayout() class FlowLayout 组件, 制作 Layout(null) .

终于为 按钮 你可以使用这个

button1.setBounds(XPosition, YPosition, WidthOFButton, HeightOFButton);