我正在尝试向框架 gui 添加一个按钮。
我尝试制作一个面板并将其添加到其中,但它不起作用。请帮忙!
这是我的代码:
import javax.swing.*;
public class Agui extends JFrame {
public Agui() {
setTitle("My Gui");
setSize(400, 400);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JButton button;
JPanel panel;
// my error lines are under the "panel" and "button"
// it says i must implement the variables. what does that mean???
panel.add(button);
}
public static void main(String[] args) {
Agui a = new Agui();
}
}
Run Code Online (Sandbox Code Playgroud)