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

📄 drawcircle.java

📁 java21pro_source 21天学通java2全书源代码
💻 JAVA
字号:
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class DrawCircle extends JFrame {
    public DrawCircle(String argR, String argX, String argY, String argColor) {
        super("DrawCircle");
        setSize(350, 250);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        CirclePanel cp = new CirclePanel(argR, argX, argY, argColor);
        Container pane = getContentPane();
        pane.add(cp);
        setVisible(true);
    }

    public static void main(String[] arguments) {
        if (arguments.length < 3) {
            System.out.println("Usage: java DrawCircle radius x y color");
            System.exit(0);
        } else {
            DrawCircle dc = new DrawCircle(arguments[0], arguments[1],
                arguments[2], arguments[3]);
        }
    }
}

class CirclePanel extends JPanel {
    int radius, x, y;
    Color color;

    public CirclePanel(String inRadius, String inX, String inY, String inColor) {
        super();
        if (inRadius == null)
            radius = 100;
        if (inX == null)
            x = 110;
        if (inY == null)
            y = 110;
        if (inColor == null)
            color = Color.blue;
        try {
            radius = Integer.parseInt(inRadius);
            x = Integer.parseInt(inX);
            y = Integer.parseInt(inY);
            color = Color.decode(inColor);
        } catch (NumberFormatException e) {
            System.out.println("Error" + e.getMessage());
        }
    }

    public void paintComponent(Graphics comp) {
        Graphics2D comp2D = (Graphics2D)comp;
        comp2D.setColor(Color.white);
        comp2D.fillRect(0, 0, getSize().width, getSize().height);
        comp2D.setColor(color);
        Ellipse2D.Float circle = new Ellipse2D.Float(x, y, radius, radius);
        comp2D.fill(circle);
    }
}

⌨️ 快捷键说明

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