小编Rss*_*j V的帖子

如何向 JFrame Gui 添加按钮

我正在尝试向框架 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)

java swing button jframe

2
推荐指数
1
解决办法
4万
查看次数

标签 统计

button ×1

java ×1

jframe ×1

swing ×1