小编Tay*_*yre的帖子

创建一个随机生成的三角形并将其绘制到Jpanel

我在让java的swing和awt库(第一次使用它们)对我来说正常工作时遇到了很大的麻烦。基本上,我想制作一个随机生成的三角形,然后将其显示在JPanel上。我已经研究了一段时间,但似乎无法使三角形显示出来。

我有一个RandomTriangle类,就像这样:

import java.util.*;
import java.math.*;

public class RandomTriangle {

  private Random rand = new Random();

  private int x1, y1,     // Coordinates
              x2, y2,
              x3, y3;
  private double a, b, c; // Sides

  public RandomTriangle(int limit) {
    do { // make sure that no points are on the same line
      x1 = rand.nextInt(limit);
      y1 = rand.nextInt(limit);

      x2 = rand.nextInt(limit);
      y2 = rand.nextInt(limit);

      x3 = rand.nextInt(limit);
      y3 = rand.nextInt(limit);
    } while (!((x2 - x1) * (y3 - y1) == (y2 - …
Run Code Online (Sandbox Code Playgroud)

java random geometry swing awt

2
推荐指数
1
解决办法
3107
查看次数

标签 统计

awt ×1

geometry ×1

java ×1

random ×1

swing ×1