我在让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)