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();
    }
}
``
编写KY9_2java创建并显示一个标题为包含面板的Frame背景色为绿色大小为800×800的框架。在该框架的中间位置放置一个颜色为黑色、大小为200×200的面板。在该面板中放置一个按钮按钮中显示请点击我。

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

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