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; } } }
public void paint(Graphics g) { // Draw Grid g.drawRect(0, 0, 780, 580); g.drawLine(400, 0, 400, 580); g.drawLine(0, 300, 780, 300); Random rndInt = new Random(1234); // Draw Random Squares for (int k = 1; k <= 1000; k++) { int x = rndInt.nextInt(385); int y = rndInt.nextInt(275); int red = rndInt.nextInt(256); int green = rndInt.nextInt(120); int blue = rndInt.nextInt(120); g.setColor(new Color(red, green, blue)); g.fillRect(x, y, 15, 15); } // Draw Random Lines for (int k = 1; k <= 1000; k++) { int x1 = rndInt.nextInt(350); int y1 = rndInt.nextInt(300); int x2 = rndInt.nextInt(370); int y2 = rndInt.nextInt(300); g.drawLine(x1 + 400, y1, x2 + 400, y2); int red = rndInt.nextInt(100); int green = rndInt.nextInt(100); int blue = rndInt.nextInt(100); g.setColor(new Color(red, green, blue)); } // Draw Random Circles for (int k = 1; k <= 1000; k++) { int x3 = rndInt.nextInt(385); int y3 = rndInt.nextInt(272); int red = rndInt.nextInt(240); int green = rndInt.nextInt(255); int blue = rndInt.nextInt(255); g.setColor(new Color(red, green, blue)); g.drawOval(x3, y3 + 300, 11, 11); } // Draw 3-D Box { g.setColor(Color.blue); int x[] = {575, 675, 675, 575}; int y[] = {425, 425, 525, 525}; g.drawPolygon(x, y, 4); g.fillPolygon(x, y, 4); } { g.setColor(Color.yellow); int x1[] = {525, 575, 575, 525}; int y1[] = {375, 425, 525, 475}; g.drawPolygon(x1, y1, 4); g.fillPolygon(x1, y1, 4); } { g.setColor(Color.green); int x2[] = {525, 625, 625, 575}; int y2[] = {375, 375, 425, 425}; g.drawPolygon(x2, y2, 4); g.fillPolygon(x2, y2, 4); } { g.setColor(Color.red); int x3[] = {625, 625, 675}; int y3[] = {375, 425, 425}; g.drawPolygon(x3, y3, 3); g.fillPolygon(x3, y3, 3); } }