第一次在这里发帖 这个编程任务让我难过,代码如下:
import java.awt.*;
import javax.swing.*;
public class HTree extends JPanel {
private Color color = new Color((int)(Math.random() * 256), (int)(Math.random() * 256), (int)(Math.random() * 256));
public void draw(Graphics g, int n, double sz, double x, double y) {
if (n == 0) return;
double x0 = x - sz/2, x1 = x + sz/2;
double y0 = y - sz/2, y1 = y + sz/2;
// draw the 3 line segments of the H
g.setColor(color);
g.drawLine((int)x0, (int)y, (int)x1, (int)y); …Run Code Online (Sandbox Code Playgroud)