Пример #1
0
  // Creates a window and draws a traffic light inside it
  private void DrawTrafficLight() {
    // Instantiates a Drawing panel
    DrawingPanel panel = new DrawingPanel(130, 290);
    panel.setTitle("Traffic Light");

    // Get graphics from panel
    Graphics draw = panel.getGraphics();

    // Draw light housing
    drawRect(draw, 20, 20, 90, 250, Color.lightGray);

    // Draw red light
    drawCircle(draw, 30, 30, 70, Color.red);

    // Draw yellow light
    drawCircle(draw, 30, 110, 70, Color.yellow);

    // Draw green light
    drawCircle(draw, 30, 190, 70, new Color(0, 127, 0));
  }
Пример #2
0
  // Draws nested shapes from the lab
  private void drawNestedShapes() {
    // Instantiates a Drawing panel
    DrawingPanel panel = new DrawingPanel(250, 250);
    panel.setTitle("Nested Shapes");

    // Get graphics from panel
    Graphics draw = panel.getGraphics();

    // Draw green square
    drawRect(draw, 25, 25, 200, 200, Color.green);

    // Draw cyan circle
    drawCircle(draw, 25, 25, 200, Color.magenta);

    // Draw cyan diamond
    draw.setColor(Color.cyan);
    draw.fillPolygon(new int[] {125, 224, 124, 25}, new int[] {25, 124, 224, 125}, 4);

    // Draw outline around diamond
    draw.setColor(Color.black);
    draw.drawPolygon(new int[] {125, 224, 124, 25}, new int[] {25, 124, 224, 125}, 4);
  }