コード例 #1
0
  public static void main(String[] args) {
    Rectangle caja, palo;
    Ellipse verde, ambar, rojo;
    int ancho, alto, centro_x, centro_y, diametro_disco;

    ancho = 150;
    alto = 300;
    centro_x = 300;
    centro_y = 300;
    diametro_disco = ancho / 2;

    caja = new Rectangle(centro_x - ancho / 2, centro_y - alto / 2, ancho, alto);
    caja.draw();

    palo = new Rectangle(centro_x - ancho / 5 / 2, centro_y + alto / 2, ancho / 5, alto);
    palo.draw();

    palo.fill();

    verde =
        new Ellipse(
            centro_x - diametro_disco / 4,
            centro_y + diametro_disco / 2,
            diametro_disco / 2,
            diametro_disco / 2);
    verde.setColor(new Color(0, 200, 0));
    ambar =
        new Ellipse(
            centro_x - diametro_disco / 4,
            centro_y - diametro_disco / 2,
            diametro_disco / 2,
            diametro_disco / 2);
    ambar.setColor(new Color(255, 255, 0));
    rojo =
        new Ellipse(
            centro_x - diametro_disco / 4,
            centro_y - diametro_disco * 1.5,
            diametro_disco / 2,
            diametro_disco / 2);
    rojo.setColor(new Color(255, 0, 0));

    verde.fill();
    ambar.fill();
    rojo.fill();
  }
コード例 #2
0
  public Target(int x, int y) {
    level0 = new Ellipse(x, y);
    this.add(level0);
    level0.setSize(size0, size0);
    level0.setColor(Color.BLACK);

    level1 = new Ellipse(x + dx1, y + dy1);
    this.add(level1);
    level1.setSize(size1, size1);
    level1.setColor(Color.RED);

    level2 = new Ellipse(x + dx2, y + dy2);
    this.add(level2);
    level2.setSize(size2, size2);
    level2.setColor(Color.GREEN);

    this.setLocation(x, y);

    box1 = new TextBox(300, 50);
    box1.setText("Loc:" + x + "," + y);
  }