⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paintcomponentdemo.java

📁 java编程代码
💻 JAVA
字号:

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.Graphics;
import java.awt.Color;

public class PaintComponentDemo extends JFrame
{
    public static final int FRAME_WIDTH = 400;
    public static final int FRAME_HEIGHT = 400;

    private class FancyPanel extends JPanel
    {
        public void paintComponent(Graphics g)
        {
            super.paintComponent(g);
            setBackground(Color.YELLOW);
            g.drawOval(FRAME_WIDTH/4, FRAME_HEIGHT/8,
                       FRAME_WIDTH/2, FRAME_HEIGHT/6);
        }
    }

    public static void main(String[] args)
    {
        PaintComponentDemo w = new PaintComponentDemo( );
        w.setVisible(true);
    }

    public PaintComponentDemo( )
    {
        setSize(FRAME_WIDTH, FRAME_HEIGHT);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("The Oval Is in a Panel");
        setLayout(new GridLayout(2, 1));
        FancyPanel p = new FancyPanel( );
        add(p);
        JPanel whitePanel = new JPanel( );
        whitePanel.setBackground(Color.WHITE);
        add(whitePanel);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -