import java.applet.Applet;
import java.awt.*;
import java.util.Random;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
public class HelloWorldApplet extends Applet {
public void paint(Graphics g) {
// 将Graphics对象转换为Graphics2D类型
java.awt.Graphics2D g2d = (java.awt.Graphics2D) g;
// 设置线的粗细为5像素
g2d.setStroke(new BasicStroke(2));
double Q = 0;
double[] x = new double[24];
double[] y = new double[24];
double x0 = 300;
double y0 = 300;
double r = 250;
for (int i = 0; i < 24; i++) {
x[i] = x0 + r * cos(Q);
y[i] = y0 + r * sin(Q);
Q += 15;
}
g2d.setColor(generateRandomColor());
for (int i = 0; i <24 - 1 ; i++) {
for (int j = i+1; j <24 ; j++) {
g2d.drawLine((int)x[i], (int)y[i], (int)x[j], (int)y[j]);
}
}
}
public static Color generateRandomColor() {
Random random = new Random();
int red = random.nextInt(256); // 生成0到255之间的随机整数
int green = random.nextInt(256);
int blue = random.nextInt(256);
Color randomColor = new Color(red, green, blue);
return randomColor;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HelloWorldApplet</title>
</head>
<body>
<applet code = "HelloWorldApplet.class" width="600" height="800"></applet>
</body>
</html>