Beispiel #1
0
  public void paint(Graphics g) {
    // clears the area that the pannel is on
    gBuffer.setColor(Color.white);
    gBuffer.fillRect(0, 0, 65, 415);

    // pannel
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(5, 15, 60, 400);

    // color buttons
    gBuffer.setColor(Color.black); // first column
    gBuffer.fillRect(15, 20, 20, 20);
    gBuffer.setColor(Color.red);
    gBuffer.fillRect(15, 40, 20, 20);
    gBuffer.setColor(Color.blue);
    gBuffer.fillRect(15, 60, 20, 20);
    gBuffer.setColor(Color.green);
    gBuffer.fillRect(15, 80, 20, 20);
    gBuffer.setColor(Color.yellow);
    gBuffer.fillRect(15, 100, 20, 20);
    gBuffer.setColor(Color.gray); // second column
    gBuffer.fillRect(35, 20, 20, 20);
    gBuffer.setColor(Color.magenta);
    gBuffer.fillRect(35, 40, 20, 20);
    gBuffer.setColor(Color.cyan);
    gBuffer.fillRect(35, 60, 20, 20);
    gBuffer.setColor(Color.orange);
    gBuffer.fillRect(35, 80, 20, 20);
    gBuffer.setColor(Color.pink);
    gBuffer.fillRect(35, 100, 20, 20);
    gBuffer.setColor(Color.black); // draw first column button outlines
    gBuffer.drawRect(15, 20, 20, 20);
    gBuffer.drawRect(15, 40, 20, 20);
    gBuffer.drawRect(15, 60, 20, 20);
    gBuffer.drawRect(15, 80, 20, 20);
    gBuffer.drawRect(15, 100, 20, 20);
    gBuffer.fillRect(15, 20, 20, 20);
    gBuffer.drawRect(35, 20, 20, 20); // draw second column button outlines
    gBuffer.drawRect(35, 40, 20, 20);
    gBuffer.drawRect(35, 60, 20, 20);
    gBuffer.drawRect(35, 80, 20, 20);
    gBuffer.drawRect(35, 100, 20, 20);

    // pen button design
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(23, 125, 3, 20);
    penta = new Polygon();
    penta.addPoint(23, 145);
    penta.addPoint(26, 145);
    penta.addPoint(25, 148);
    gBuffer.drawPolygon(penta);

    // brush button design
    gBuffer.setColor(Color.gray);
    gBuffer.fillRect(45, 128, 3, 10);
    penta = new Polygon();
    penta.addPoint(45, 138);
    penta.addPoint(48, 138);
    penta.addPoint(51, 141);
    penta.addPoint(42, 141);
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(42, 141, 9, 5);
    gBuffer.drawLine(45, 146, 45, 144);
    gBuffer.drawLine(48, 146, 48, 143);

    // roller button design
    gBuffer.setColor(Color.black); // handle
    gBuffer.fillRect(23, 155, 3, 10);
    gBuffer.drawRect(19, 165, 9, 4);
    gBuffer.setColor(Color.white); // roller front
    gBuffer.fillOval(27, 166, 4, 4);
    gBuffer.setColor(Color.black); // roller round side
    gBuffer.drawOval(27, 166, 3, 3);

    // spray paint button design
    gBuffer.setColor(Color.black); // top of can
    penta = new Polygon();
    penta.addPoint(43, 156);
    penta.addPoint(48, 160);
    penta.addPoint(43, 163);
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.blue); // spray button
    gBuffer.fillRect(42, 155, 2, 3);
    for (int n = 0; n <= 20; n++) // paint spray
    {
      x = 39 + ((int) (3 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
      y = 157 + ((int) (3 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
      gBuffer.fillRect(x, y, 1, 1);
    }
    penta = new Polygon(); // can
    penta.addPoint(43, 163);
    penta.addPoint(48, 160);
    penta.addPoint(53, 172);
    penta.addPoint(48, 177);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black);
    gBuffer.drawPolygon(penta);

    // rubber band drawing button design (20,185,30,205);
    gBuffer.setColor(Color.black);
    for (int a = 18, b = 200; a <= 35; a += 4, b += 2) {
      gBuffer.drawLine(18, 183, a, b);
    }

    // eraser button design
    gBuffer.setColor(Color.yellow); // top
    penta = new Polygon();
    penta.addPoint(45, 185);
    penta.addPoint(50, 185);
    penta.addPoint(45, 200);
    penta.addPoint(40, 200);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black); // outline
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.yellow); // side
    penta = new Polygon();
    penta.addPoint(50, 185);
    penta.addPoint(45, 200);
    penta.addPoint(48, 204);
    penta.addPoint(52, 189);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black); // outline
    gBuffer.drawPolygon(penta);
    penta = new Polygon(); // front
    penta.addPoint(40, 200);
    penta.addPoint(45, 200);
    penta.addPoint(48, 204);
    penta.addPoint(43, 204);
    gBuffer.drawPolygon(penta);

    // clear button design
    gBuffer.setColor(Color.black);
    gBuffer.setFont(new Font("Arial", Font.BOLD, 20));
    gBuffer.drawString("Clear", 10, 239);
    gBuffer.drawRect(10, 220, 50, 25);

    gBuffer.setColor(Color.cyan);
    switch (numSize) {
      case 1:
        gBuffer.drawRect(15, 120, 20, 30);
        break;
      case 2:
        gBuffer.drawRect(35, 120, 20, 30);
        break;
      case 3:
        gBuffer.drawRect(15, 150, 20, 30);
        break;
      case 4:
        gBuffer.drawRect(35, 150, 20, 30);
        break;
      case 5:
        gBuffer.drawRect(15, 180, 20, 30);
        break;
      case 6:
        gBuffer.drawRect(35, 180, 20, 30);
        break;
    }

    if ((numSize == 4) || (numSize == 6)) {
      // draw different size buttons for spray paint, eraser, and rubber band
      gBuffer.setColor(Color.white);
      gBuffer.fillRect(20, 265, 35, 75);
      gBuffer.setColor(Color.cyan);
      switch (size) {
        case 1:
          gBuffer.drawRect(26, 271, 18, 18);
          break;
        case 2:
          gBuffer.drawRect(26, 291, 18, 18);
          break;
        case 3:
          gBuffer.drawRect(26, 311, 18, 18);
      }
      gBuffer.setColor(Color.black);
      gBuffer.drawRect(20, 265, 30, 70); // size pannel
      gBuffer.drawRect(25, 270, 20, 20); // small
      gBuffer.drawRect(25, 290, 20, 20); // medium
      gBuffer.drawRect(25, 310, 20, 20); // large

      if (numSize == 4) {
        for (int n = 0; n <= 20; n++) {
          x = 35 + ((int) (4 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 280 + ((int) (4 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        for (int n = 0; n <= 40; n++) {
          x = 34 + ((int) (6 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 300 + ((int) (6 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        for (int n = 0; n <= 70; n++) {
          x = 35 + ((int) (8 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 319 + ((int) (8 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        switch (size) {
          case 1:
            s = 4;
            break;
          case 2:
            s = 6;
            break;
          case 3:
            s = 8;
        }
      } else if (numSize == 6) {
        gBuffer.drawRect(33, 278, 4, 4);
        gBuffer.drawRect(32, 297, 7, 7);
        gBuffer.drawRect(30, 315, 10, 10);

        switch (size) {
          case 1:
            s = 4;
            break;
          case 2:
            s = 7;
            break;
          case 3:
            s = 10;
        }
      }
    } else {
      gBuffer.setColor(Color.white);
      gBuffer.fillRect(20, 265, 35, 75);
    }

    // draw pannel and buttons
    g.drawImage(virtualMem, 0, 0, this);

    // changing what color it draws with
    switch (numColor) {
      case 1:
        gBuffer.setColor(Color.black);
        break;
      case 2:
        gBuffer.setColor(Color.red);
        break;
      case 3:
        gBuffer.setColor(Color.blue);
        break;
      case 4:
        gBuffer.setColor(Color.green);
        break;
      case 5:
        gBuffer.setColor(Color.yellow);
        break;
      case 6:
        gBuffer.setColor(Color.gray);
        break;
      case 7:
        gBuffer.setColor(Color.magenta);
        break;
      case 8:
        gBuffer.setColor(Color.cyan);
        break;
      case 9:
        gBuffer.setColor(Color.orange);
        break;
      case 10:
        gBuffer.setColor(Color.pink);
        break;
      case 11:
        gBuffer.setColor(Color.white);
        break;
      default:
        gBuffer.setColor(Color.black);
    }

    // changing how it draws
    switch (numDraw) {
      case 1: // clear drawing
        gBuffer.setColor(Color.white);
        gBuffer.fillRect(0, 0, appletWidth, appletHeight);
        g.drawImage(virtualMem, 0, 0, this);
        numDraw = 0;
        repaint();
        break;
      default:
        switch (numSize) {
          case 1: // draw with pen
            if (!first) {
              gBuffer.drawLine(oldX, oldY, newX, newY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 2: // draw with brush
            if (!first) {
              gBuffer.fillRect(oldX, oldY, 4, 4);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 3: // draw with roller
            if (!first) {
              gBuffer.fillRect(oldX, oldY, 10, 10);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 4: // draw with spray paint
            if (!first) {
              for (int n = 0; n <= 20; n++) {
                x = oldX + ((int) (s * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
                y = oldY + ((int) (s * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
                gBuffer.fillRect(x, y, 1, 1);
                g.drawImage(virtualMem, 0, 0, this);
              }
            } else first = false;

            break;
          case 5: // draw with rubber band style
            if (!first) {
              gBuffer.drawLine(startX, startY, endX, endY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 6: // eraser drawer
            if (!first) {
              gBuffer.fillRect(oldX, oldY, s, s);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          default: // default to drawing with pen
            if (!first) {
              gBuffer.drawLine(oldX, oldY, newX, newY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
        }
    }
  }
Beispiel #2
0
  public void paint(Graphics g) {

    // Draw Grid
    g.drawRect(10, 10, 780, 580);
    g.drawLine(400, 10, 400, 590);
    g.drawLine(10, 300, 790, 300);

    Random rnd = new Random(1234);
    for (int k = 10; k <= 400; k += 10) { // The first box lines
      g.drawLine(k, 20, k, 290);
    } // The dimentions of the lines
    for (int k = 10; k <= 290; k += 10) { // The second box lines
      g.drawLine(420, k, 770, k); // The dimestions
      int red = rnd.nextInt(256); // The colors
      int green = rnd.nextInt(256);
      int blue = rnd.nextInt(256);
      g.setColor(new Color(red, green, blue)); // The randomness of colors
    }
    for (int k = 1; k <= 100; k++) { // The 3rd circles
      int x = rnd.nextInt(330); // the random of x lo
      int y = rnd.nextInt(230); // the randm of y
      int red = rnd.nextInt(256); // the random of colors
      int green = rnd.nextInt(256);
      int blue = rnd.nextInt(256);
      g.setColor(new Color(red, green, blue));
      g.fillOval(x + 10, y + 300, 50, 50);
    } // the place of all the ovals

    Polygon side1 = new Polygon(); // blue side of cube
    side1.addPoint(600, 410);
    side1.addPoint(635, 410);
    side1.addPoint(635, 480);
    side1.addPoint(600, 445);
    g.setColor(Color.blue);
    g.fillPolygon(side1);
    Polygon side2 = new Polygon(); // green side of cube
    side2.addPoint(510, 380);
    side2.addPoint(550, 410);
    side2.addPoint(550, 495);
    side2.addPoint(510, 455);
    g.setColor(Color.green);
    g.fillPolygon(side2);
    Polygon side3 = new Polygon(); // yellow side of cube
    side3.addPoint(550, 445);
    side3.addPoint(600, 445);
    side3.addPoint(635, 480);
    side3.addPoint(550, 495);
    g.setColor(Color.yellow);
    g.fillPolygon(side3);
    Polygon side4 = new Polygon(); // red side of cube
    side4.addPoint(510, 380);
    side4.addPoint(550, 410);
    side4.addPoint(635, 410);
    side4.addPoint(600, 380);
    g.setColor(Color.red);
    g.fillPolygon(side4);
    // TODO Auto-generated method stub

    // TODO Auto-generated method stub

  }