import javax.swing.*;
import java.awt.*;

public class KY9_2 extends JFrame {

    public KY9_2() {
        setTitle('包含面板的Frame');
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(800, 800);
        setBackground(Color.GREEN);

        JPanel panel = new JPanel();
        panel.setBackground(Color.BLACK);
        panel.setPreferredSize(new Dimension(200, 200));
        add(panel, BorderLayout.CENTER);

        JButton button = new JButton('请点击我');
        panel.add(button);

        setVisible(true);
    }

    public static void main(String[] args) {
        new KY9_2();
    }
}
Java Swing 框架:创建带面板和按钮的窗口

原文地址: https://www.cveoy.top/t/topic/ogdn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录