Java PaintComponent不使用JButtons-已修复

Java PaintComponent不使用JButtons-已修复,java,layout,jframe,jbutton,Java,Layout,Jframe,Jbutton,编辑:谢谢大家,你们真的帮助了我。我需要做的最后一件事是使面板布局为空,这样JButton就可以移动了。谢谢大家! 我的paintComponents内容没有显示在我的程序屏幕上,我想我可能对布局做了一些错误,但我不明白为什么我的抽绳“计算器”没有显示出来。以下是我的代码(我从另一个名为Launcher的类启动窗口): 这是Launcher.java package uusi.projekti.juttu; public class Launcher { public static

编辑:谢谢大家,你们真的帮助了我。我需要做的最后一件事是使面板布局为空,这样JButton就可以移动了。谢谢大家!

我的paintComponents内容没有显示在我的程序屏幕上,我想我可能对布局做了一些错误,但我不明白为什么我的抽绳“计算器”没有显示出来。以下是我的代码(我从另一个名为Launcher的类启动窗口):

这是Launcher.java

package uusi.projekti.juttu;

public class Launcher {

    public static void main(String[] args) {
        new Window();
    }
}

试着这样做:

公共类窗口实现可运行{

public Window() {

    JButton button = new JButton("=");
    button.setBounds(530, 510, 50, 50);
    button.setLayout(null);
    button.setVisible(true);

    JPanel panel = new drawPanel();

    JFrame frame = new JFrame("Title");

//  frame.setLayout(new FlowLayout());
    frame.setVisible(true);
    frame.setSize(600, 600);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.add(panel);

    panel.add(button);
}

你的主要方法在哪里?编辑了原始帖子,因为代码在注释中未格式化。计算器字符串显示并显示按钮,但我无法更改按钮的位置。我是否需要使用其他类型的代码来更改按钮或其他布局的位置?
public Window() {

    JButton button = new JButton("=");
    button.setBounds(530, 510, 50, 50);
    button.setLayout(null);
    button.setVisible(true);

    JPanel panel = new drawPanel();

    JFrame frame = new JFrame("Title");

//  frame.setLayout(new FlowLayout());
    frame.setVisible(true);
    frame.setSize(600, 600);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.add(panel);

    panel.add(button);
}