Example #1
0
  @Override
  public void draw(Canvas canvas) {

    Color currColor = canvas.getColor();

    canvas.setColor(Color.GREEN);
    int width = mRect.widht() * mHealth / mMaxHelth;
    glPushMatrix();
    glTranslated(mX, mY, 0);
    glBegin(GL_QUADS);
    glVertex2d(1, 1);
    glVertex2d(width, 1);
    glVertex2d(width, mRect.height() - 1);
    glVertex2d(1, mRect.height() - 1);
    glEnd();
    glTranslated(0, 0, 0);
    glPopMatrix();
    canvas.setColor(currColor);

    canvas.setColor(Color.RED);
    glPushMatrix();
    glTranslated(mX, mY, 0);
    glBegin(GL_QUADS);
    glVertex2d(1, 1);
    glVertex2d(mRect.widht() - 1, 1);
    glVertex2d(mRect.widht() - 1, mRect.height() - 1);
    glVertex2d(1, mRect.height() - 1);
    glEnd();
    glTranslated(0, 0, 0);
    glPopMatrix();
    canvas.setColor(currColor);

    super.draw(canvas);
  }
  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();
  }
  public static void main(String[] args) {

    // Ex041_abstract

    Circle c1 = new Circle();
    c1.name = "원1";
    c1.draw();
    c1.erase();

    Rectangle r1 = new Rectangle();
    r1.name = "사각형1";
    r1.draw();
    r1.erase();
  }
Example #4
0
  public static void main(String[] args) {
    Circle c = new Circle();
    Triangle t = new Triangle();
    Rectangle r = new Rectangle();

    // 1. 각각의 도형 그리기
    c.draw();
    t.draw();
    r.draw();

    // 2. 각각의 도형 지우기
    c.delete();
    t.delete();
    r.delete();
  }
Example #5
0
 public void draw(Graphics2D g) {
   super.draw(g);
   g.setColor(fontColor);
   g.setFont(font);
   g.drawString(text, 0 + font.getSize() / 2, (int) h - font.getSize() / 4);
 }