drawcircle.java
来自「21Java教程的全部源代码 北京邮电大学出版」· Java 代码 · 共 39 行
JAVA
39 行
import java.awt.*;
import java.awt.geom.*;
public class DrawCircle extends javax.swing.JApplet {
int radius, x, y;
Color color;
public void init() {
String inRadius = getParameter("radius");
String inX = getParameter("x");
String inY = getParameter("y");
String inColor = getParameter("color");
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) {
showStatus("Parameter error" + e.getMessage());
}
}
public void paint(Graphics screen) {
Graphics2D screen2D = (Graphics2D)screen;
screen2D.setColor(Color.white);
screen2D.fillRect(0, 0, getSize().width, getSize().height);
screen2D.setColor(color);
Ellipse2D.Float circle = new Ellipse2D.Float(x, y, radius, radius);
screen2D.fill(circle);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?