更新时间:2023-12-05 18:03:52
您的班级 DrawPanel
仅限于 main
方法,对你的构造函数不可见。
Your class DrawPanel
is confined to the scope of your main
method and is not visible to your constructor.
你需要移动 DrawPanel
退出主
方法,然后将其添加到 JFrame
:
You need to move DrawPanel
out of your main
method, then add it to your JFrame
:
frame.add(panel);
此外,***调用 frame.setVisible(true)
添加完所有组件后。
Also, better to call frame.setVisible(true)
after all components have been added.