public void paint(Graphics g) { // chose Font with selected value f = new Font( lFont.getSelectedItem(), lStyle.getSelectedIndex(), Integer.parseInt(lSize.getSelectedItem())); // Clear Background g.setColor(Color.white); g.fillRect(0, 85, 400, 200); g.setColor(Color.black); if (f != null) { g.setFont(f); } g.drawString(sString.getText(), 20, 120); // Get Unicode char format FFFF in textfield sChar String s = sChar.getText(); char c; try { c = (char) Integer.parseInt(s, 16); if (Character.isDefined(c)) g.drawString("char \\u" + s + " is " + c, 20, 180); else g.drawString("char \\u" + s + " not exist", 20, 180); } catch (Exception e) { // Can parse this string g.drawString("" + e, 20, 180); } }
public void displayScore2( Graphics g, int cx, int cy, int sx1, int sy1, int sx2, int sy2, int sx3, int sy3) { g.setFont(scoreFont); g.setColor(Color.WHITE); g.drawImage(new ImageIcon("InGameMenu/coin.png").getImage(), cx, cy, this); g.drawString("" + coins, sx1, sy1); g.drawString("Score: " + score, sx2, sy2); g.drawString("Height: " + height + " m", sx3, sy3); }
public void stare_paint(Graphics g) { int licznik = 0; test++; for (int i = 0; i < 100; i += 3) { g.setColor(kolory[licznik++ % kolory.length]); g.fillRoundRect(i, i, 400 - i * 2, 200 - i * 2, 10, 10); } g.setFont(f); g.setColor(kolor); g.drawString("Trebuchet MS jest " + test, 50, 100); }
public void gameOverMenu( Graphics g) { // CHANGE THIS TO INCLUDE HIGHSCORES AND STUFF AFTER TEXTFILES ARE MADE // Menu that shows up when user gets Game Over if (pause == true && die == true) { g.drawImage( new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); // Graphics stuff g.setFont(scoreFont); g.setColor(Color.BLACK); g.drawImage(new ImageIcon("InGameMenu/GameOver.png").getImage(), 10, 200, this); displayScore2(g, 115, 350, 185, 385, 110, 440, 110, 490); // Shows stats g.drawImage(menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws menu button } }
public Graphics startPaint(Graphics sysgraph) { mSystemGraphics = sysgraph; Dimension d = getSize(); if ((mActiveOffscreenImage == null) || (d.width != mOffscreenSize.width) || (d.height != mOffscreenSize.height)) { mActiveOffscreenImage = createImage(d.width, d.height); mActiveOffscreenGraphics = mActiveOffscreenImage.getGraphics(); mOffscreenSize = d; mActiveOffscreenGraphics.setFont(getFont()); } return mActiveOffscreenGraphics; }
public static void titlePage(Graphics g, String name, int period) { Expo.setBackground(g, Expo.gold); Expo.setColor(g, Expo.white); Expo.fillRectangle(g, 100, 100, 900, 550); Expo.setColor(g, Expo.red); Font title = new Font("Algerian", Font.BOLD, 48); g.setFont(title); g.drawString("Flags of the World", 225, 240); Expo.setColor(g, Expo.blue); g.drawString("by: " + name, 225, 340); Expo.setColor(g, Expo.green); g.drawString("Period: " + period, 225, 440); Expo.delay(3000); // Wait 3 second before showing first flag. }
public void paint(Graphics g) { g.setFont(bigFont); g.drawString("Shapes and Colors", 80, 20); g.setColor(redColor); g.drawRect(100, 100, 100, 100); g.fillRect(110, 110, 80, 80); g.setColor(weirdColor); g.fillArc(120, 120, 60, 60, 0, 360); g.setColor(Color.yellow); g.drawLine(140, 140, 160, 160); g.setColor(Color.black); }
public void CalculateSize(Graphics g) { oldwidth = sx2 - sx1; oldheight = sy2 - sy1; Font testfont; testfont = new Font("TimesRoman", Font.PLAIN, 100); g.setFont(testfont); int width = g.getFontMetrics().stringWidth(short_name); int height = g.getFontMetrics().getHeight(); double xratio = ((double) (oldwidth)) / ((double) width); double yratio = ((double) (oldheight)) / ((double) height); double fsize; if (xratio > yratio) { // use yratio to calculate size fsize = 100.0 * yratio; } else fsize = 100.0 * xratio; if (fsize < 1.0) fsize = 1.0; fsize = fsize * Caption.FontScale; currfont = new Font("TimesRoman", Font.PLAIN, (int) fsize); g.setFont(currfont); xoff = (sx2 - sx1 - g.getFontMetrics().stringWidth(short_name)) / 2; yoff = g.getFontMetrics().getDescent(); }
public void Draw() { Graphics g; Color cl; int c; int xdiff, ydiff; g = parentarea.screen; if ((Resize) || (ResizeAll)) Calculate_Coors(); c = ((int) activation) * 255 / 100; if (c < 0) c = 0; if (c > 255) c = 255; cl = new Color(c, c, c); if (oldclamp != clamp) { g.setColor(Color.white); g.fillRect(sx1, sy1, 1 + sx2 - sx1, 1 + sy2 - sy1); } g.setColor(cl); g.fillOval(sx1, sy1, sx2 - sx1, sy2 - sy1); g.setColor(Color.black); if (activation == (double) 100.0) g.setColor(Color.red); g.drawOval(sx1, sy1, sx2 - sx1, sy2 - sy1); if (clamp) { xdiff = (sx2 - sx1); ydiff = (sy2 - sy1); g.drawRect(sx1, sy1, xdiff, ydiff); } if ((Resize) || (ResizeAll)) CalculateSize(g); g.setFont(currfont); if (activation > 50.0) g.setColor(Color.black); else g.setColor(Color.white); if (foreground != null) g.setColor(foreground); g.drawString(short_name, sx1 + xoff, sy2 - yoff); Redraw = false; Resize = false; if (oldclamp != clamp) { // draw all bonds - as they will have been erased oldclamp = clamp; for (int x = 0; x < outgoing_links.size(); x++) { slipnet_link s = (slipnet_link) outgoing_links.elementAt(x); s.Draw(); } } }
public static void showName(Graphics g, String name) { FontMetrics metrics = g.getFontMetrics(countryName); int nameWidth = metrics.stringWidth(name); int boxWidth = nameWidth + 20; int xName = 950 - nameWidth; int xBox = xName - 10; Expo.setColor(g, Expo.white); Expo.fillRectangle(g, xBox, 50, xBox + boxWidth, 120); Expo.setColor(g, Expo.black); Expo.drawRectangle(g, xBox, 50, xBox + boxWidth, 120); for (int j = 1; j <= 5; j++) { Expo.drawLine(g, xBox + j, 120 + j, xBox + boxWidth + j, 120 + j); Expo.drawLine(g, xBox + boxWidth + j, 50 + j, xBox + boxWidth + j, 120 + j); } Expo.drawRectangle(g, xBox + 1, 51, xBox + boxWidth + 1, 121); g.setFont(countryName); g.drawString(name, xName, 100); Expo.delay(2000); // Wait 2 second before showing next flag. }
public void update(Graphics g) { Dimension d = size(); if (d.width < 1 || d.height < 1) return; if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) { offscreen = createImage(d.width, d.height); offscreensize = d; offGraphics = offscreen.getGraphics(); } offGraphics.setColor(getBackground()); offGraphics.fillRect(0, 0, d.width, d.height); Font font = new Font("Dialog", Font.PLAIN, 10); offGraphics.setFont(font); fm = offGraphics.getFontMetrics(); paint(offGraphics); g.drawImage(offscreen, 0, 0, null); }
// ------------------------------------------------------------------------------------------------------------------------------------ // In game menus public void pauseMenu(Graphics g) { // Pause menu if (pause == true && lvlClear == false) { g.setFont(scoreFont); g.setColor(Color.BLACK); g.drawImage(new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); g.drawString("P A U S E D", 155, 200); displayScore2(g, 115, 350, 185, 380, 110, 440, 110, 490); // Displays stats g.drawImage( resumeB.getPic(mx, my), resumeB.getX(), resumeB.getY(), this); // Draws the resume button g.drawImage( menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws the back to menu button if (musicOn == true) { // Draws the mute or unmute button (based on if music is on or not) g.drawImage(muteB.getPic(mx, my), muteB.getX(), muteB.getY(), this); } if (musicOn == false) { g.drawImage(unmuteB.getPic(mx, my), unmuteB.getX(), unmuteB.getY(), this); } } }
public void paint(Graphics g) { // int numDoors=0; int rX = player.getRelativeX(); int rY = player.getRelativeY(); boolean notInBuilding = true; bufferGraphics.clearRect(0, 0, dim.width, dim.width); bufferGraphics.setColor(Color.WHITE); r2.setLocation(20 + rX, 20 + rY); // Iterator<Objects> iterator1 = entities.iterator();//size is the last index, therefore it // starts at the end // while(iterator1.hasNext()){ // iterator1.next().update(rX, rY); // bufferGraphics.drawImage(iterator1.next().image, iterator1.next().blockX+rX, // iterator1.next().blockX+rY, null); // } for (int x = 0; x < buildings.size(); x++) { buildings.get(x).update(rX, rY); player.onDoor(player.r, buildings.get(x).door); player.collideOn(player.r, buildings.get(x)); if (player.inHouse(player.r, buildings.get(x).inside)) { notInBuilding = false; } // if(notInBuilding){ // bufferGraphics.drawImage(buildings.get(x).image, // buildings.get(x).blockX+rX,buildings.get(x).blockY+rY, null); // }else{ // bufferGraphics.drawImage(buildings.get(x).innerImage, // buildings.get(x).blockX+rX,buildings.get(x).blockY+rY, null); // } // bufferGraphics.fillRect(entities.get(x).bounds.x, entities.get(x).bounds.y, // entities.get(x).bounds.width, entities.get(x).bounds.height); } bufferGraphics.setFont(new Font("Arial", Font.PLAIN, 20)); // String m1 = new Boolean(player.canMove('w')).toString(); bufferGraphics.drawString(message, 0, 170); // bufferGraphics.fillRect(r2.x, r2.y, r2.width, r2.height); // player.collideOn(player.r, r2); // ***Image log1 = new ImageIcon(getClass().getResource("logTest.png")).getImage(); // ***bufferGraphics.drawImage(log1, (int)r2.getX(), (int)r2.getY(), null); // bufferGraphics.drawLine((int)player.N.getX1(), (int)player.N.getY1(), (int)player.N.getX2(), // (int)player.N.getY2()); // bufferGraphics.drawLine((int)player.E.getX1(), (int)player.E.getY1(), (int)player.E.getX2(), // (int)player.E.getY2()); // bufferGraphics.drawLine((int)player.S.getX1(), (int)player.S.getY1(), (int)player.S.getX2(), // (int)player.S.getY2()); // bufferGraphics.drawLine((int)player.W.getX1(), (int)player.W.getY1(), (int)player.W.getX2(), // (int)player.W.getY2()); // bufferGraphics.setColor(Color.RED); // bufferGraphics.drawLine((int)player.NI.getX1(), (int)player.NI.getY1(), // (int)player.NI.getX2(), (int)player.NI.getY2()); // bufferGraphics.drawLine((int)player.EI.getX1(), (int)player.EI.getY1(), // (int)player.EI.getX2(), (int)player.EI.getY2()); // bufferGraphics.drawLine((int)player.SI.getX1(), (int)player.SI.getY1(), // (int)player.SI.getX2(), (int)player.SI.getY2()); // bufferGraphics.drawLine((int)player.WI.getX1(), (int)player.WI.getY1(), // (int)player.WI.getX2(), (int)player.WI.getY2()); if (notInBuilding) { Image thebg = new ImageIcon(getClass().getResource("grassbackingdev.png")).getImage(); bufferGraphics.drawImage(thebg, 0 + rX, 0 + rY, null); } player.update(); int setX = Math.abs(player.relativeX); int setY = Math.abs(player.relativeY); if (player.relativeX > 0) { setX = -setX; } if (player.relativeY > 0) { setY = -setY; } if (notInBuilding) { for (int x = 0; x < entities.size(); x++) { entities.get(x).update(rX, rY); bufferGraphics.drawImage( entities.get(x).image, entities.get(x).blockX + rX, entities.get(x).blockY + rY, null); player.collideOn(player.r, entities.get(x)); if (entities.get(x).health <= 0) { if (entities.get(x).material == "Wood") wood += entities.get(x).matsReturn; if (entities.get(x).material == "Stone") stone += entities.get(x).matsReturn; entities.remove(x); } // bufferGraphics.fillRect(entities.get(x).bounds.x, entities.get(x).bounds.y, // entities.get(x).bounds.width, entities.get(x).bounds.height); } } for (int x = 0; x < buildings.size(); x++) { if (notInBuilding) { bufferGraphics.drawImage( buildings.get(x).image, buildings.get(x).blockX + rX, buildings.get(x).blockY + rY, null); } else { bufferGraphics.drawImage( buildings.get(x).innerImage, buildings.get(x).blockX + rX, buildings.get(x).blockY + rY, null); } } if (notInBuilding) { for (int x = 0; x < npcArray.size(); x++) { for (int e = 0; e < entities.size(); e++) { npcArray.get(x).detectEntities(entities.get(e)); if (entities.get(e).health <= 0) { entities.remove(e); } } npcArray.get(x).update(rX, rY, setX + 92, setY + 82); bufferGraphics.drawImage( npcArray.get(x).graphic, npcArray.get(x).npcX + rX, npcArray.get(x).npcY + rY, null); if (npcArray.get(x).isDead()) { npcArray.remove(x); } else if (npcArray.get(x).hitBox.intersects(player.r)) { player.health -= 25; npcArray.remove(x); } } } for (int x = 0; x < playerAttack.size(); x++) { playerAttack.get(x).update(rX, rY); bufferGraphics.drawImage( playerAttack.get(x).graphic, playerAttack.get(x).currentX + rX, playerAttack.get(x).currentY + rY, null); for (int y = 0; y < npcArray.size(); y++) { if (playerAttack.get(x).hitBox.intersects(npcArray.get(y).hitBox)) { npcArray.get(y).health -= 25; playerAttack.get(x).hasHit = true; } } if (playerAttack.get(x).isDead()) { playerAttack.remove(x); } } player.notOnDoor = true; if (player.moving) { bufferGraphics.drawImage( player.getImage().getImage(), player.getCharx(), player.getChary(), null); // TODO } else { bufferGraphics.drawImage(player.getIdle(), player.getCharx(), player.getChary(), null); } if (Ghosting) { if (player.face == 1) { bufferGraphics.drawImage(player.getResource(resource), 104, 87, null); // EAST } if (player.face == 2) { bufferGraphics.drawImage(player.getResource(resource), 94, 106, null); // SOUTH*94,106 } if (player.face == 3) { bufferGraphics.drawImage(player.getResource(resource), 84, 87, null); // WEST84,87 } if (player.face == 4) { bufferGraphics.drawImage(player.getResource(resource), 94, 75, null); // NORTH94,75 } } if (player.health <= 0) { bufferGraphics.drawString("You are dead", 10, 90); stop(); } bufferGraphics.setFont(new Font("Arial", Font.PLAIN, 9)); bufferGraphics.setColor(new Color(160, 82, 45)); bufferGraphics.fillRect(0, 2, 8, 8); bufferGraphics.setColor(new Color(105, 105, 105)); bufferGraphics.fillRect(0, 12, 8, 8); bufferGraphics.drawImage(statusBar, 0, 22, null); bufferGraphics.setColor(Color.WHITE); bufferGraphics.drawString(String.format("%d", wood), 18, 10); bufferGraphics.drawString(String.format("%d", stone), 18, 20); bufferGraphics.drawString(String.format("%d", player.health), 18, 30); // bufferGraphics.fillRect((int)player.r.getX(), (int)player.r.getY(), // (int)player.r.getWidth(),(int)player.r.getHeight()); // bufferGraphics.fillRect(player.r.x, player.r.x, player.r.width, player.r.height); g.drawImage(offScreen, 0, 0, this); // if(drawConsole){ // message = String.format("wood: %d", wood); // } }
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) { g.setColor(Color.red); g.setFont(new Font("Arial", Font.BOLD, 25)); g.drawString("Registrar nueva venta", 60, 60); }
/** The method to call when the thread starts */ public void run() { boolean draw = true; FontMetrics fm; Rectangle r; int sw = 0; int sa = 0; int x = 0; int y = 0; setPriority(Thread.MIN_PRIORITY); while (true) { if (newmessage != null && draw) { message = newmessage; newmessage = null; } if (lg == null) { lg = g2d.getGraphics(); if (lg != null) lg = lg.create(); } if (lg != null) { if (f != null) lg.setFont(f); fm = lg.getFontMetrics(lg.getFont()); sw = fm.stringWidth(message); sa = fm.getAscent(); } else { draw = false; } if (draw) { lg.setColor(foreground); r = g2d.bounds(); x = r.x + (r.width - sw) / 2; y = r.y + (r.height + sa) / 2; lg.drawString(message, x, y); g2d.repaint(); try { sleep(visible); } catch (Exception e) { } } else { if (lg != null) { lg.setColor(g2d.getBackground()); lg.drawString(message, x, y); g2d.repaint(); } try { sleep(invisible); } catch (Exception e) { } } draw = !draw; } }
public void drawBlock(Graphics g, int r, int c, int mode) { Color curr = g.getColor(); g.setColor(Color.black); int inc = 2; int xpos = inc + (c * wt), ypos = inc + (r * ht); switch (mode) { case 1: { // drawn on a square with an unclicked // bomb drawBomb(g, xpos, ypos); break; } case 2: { // draws a cell with a number on it g.setColor(Color.lightGray); g.fillRect(xpos, ypos, wt, ht); if (field[r][c] > 0) { g.setFont(new Font("Serif", Font.BOLD, 12)); g.setColor(list[field[r][c] - 1]); g.drawString(field[r][c] + "", xpos + 5, ypos + 12); } } break; case 3: { // drawn on the square where the bomb was clicked g.setColor(Color.red); g.fillRect(xpos, ypos, wt, ht); g.setColor(Color.black); drawBomb(g, xpos, ypos); } break; case 4: { // draws a plain unrevealed cell g.setColor(Color.lightGray); g.fill3DRect(xpos, ypos, wt, ht, true); } break; case 5: { // a Flag. g.setColor(Color.lightGray); g.fill3DRect(xpos, ypos, wt, ht, true); g.setColor(Color.red); g.fillRect(xpos + 4, ypos + 3, 4, 4); g.setColor(Color.red.darker()); g.drawLine(xpos + 8, ypos + 3, xpos + 8, ypos + 6); g.drawLine(xpos + 8, ypos + 6, xpos + 5, ypos + 6); g.drawLine(xpos + 6, ypos + 5, xpos + 7, ypos + 5); g.drawLine(xpos + 7, ypos + 5, xpos + 7, ypos + 4); g.setColor(new Color(128, 128, 128)); g.drawLine(xpos + 5, ypos + 12, xpos + 11, ypos + 12); g.drawLine(xpos + 7, ypos + 11, xpos + 9, ypos + 11); g.setColor(Color.black); g.drawLine(xpos + 8, ypos + 7, xpos + 8, ypos + 11); g.drawLine(xpos + 6, ypos + 12, xpos + 10, ypos + 12); } break; case 6: { // A red cross - flag over non mine block g.setColor(Color.red); g.drawLine(xpos + 3, ypos + 3, xpos + 11, ypos + 11); g.drawLine(xpos + 4, ypos + 3, xpos + 12, ypos + 11); g.drawLine(xpos + 12, ypos + 3, xpos + 4, ypos + 11); g.drawLine(xpos + 3, ypos + 11, xpos + 11, ypos + 3); g.setColor(Color.red.darker()); g.drawLine(xpos + 3, ypos + 12, xpos + 4, ypos + 12); g.drawLine(xpos + 4, ypos + 12, xpos + 7, ypos + 9); g.drawLine(xpos + 8, ypos + 9, xpos + 11, ypos + 12); g.drawLine(xpos + 11, ypos + 12, xpos + 12, ypos + 12); g.drawLine(xpos + 3, ypos + 4, xpos + 6, ypos + 7); g.drawLine(xpos + 12, ypos + 4, xpos + 9, ypos + 7); } break; case 7: { g.setColor(Color.lightGray); g.fillRect(xpos, ypos, wt, ht); } break; } g.setColor(curr); }
public void drawTitleScreen(Graphics g) { // color the screen g.setColor(Color.red); g.fillRect(posx_cursor - 5, posy_cursor - 5, 150, 50); g.fillRect(posx_cursor + 5, posy_cursor - 5, 150, 50); // Place the body of the drawing method here g.setColor(Color.white); g.setFont(new Font("Vineta BT", Font.ITALIC, 50)); g.drawString("SUPER", 125, 80); g.drawString("SMASH", 120, 130); g.drawString("BRICKS", 115, 180); g.setFont(new Font("Vineta BT", Font.PLAIN, 50)); g.drawString("SUPER", 125, 80); g.drawString("SMASH", 120, 130); g.drawString("BRICKS", 115, 180); g.setFont(new Font("Arial", Font.PLAIN, 20)); g.setColor(Color.white); g.fillRect(posx_new, posy_new, 150, 40); g.setColor(Color.black); g.fillRect(185, 255, 140, 30); g.setColor(Color.white); g.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20)); g.drawString("New Game", 205, 275); g.setColor(Color.white); g.fillRect(posx_diffi, posy_diffi, 150, 40); g.setColor(Color.black); g.fillRect(185, 305, 140, 30); g.setColor(Color.white); g.drawString("Difficulty", 215, 325); g.setColor(Color.white); g.fillRect(posx_controls, posy_controls, 150, 40); g.setColor(Color.black); g.fillRect(185, 355, 140, 30); g.setColor(Color.white); g.drawString("Controls", 217, 375); g.setColor(Color.white); g.fillRect(posx_credits, posy_credits, 150, 40); g.setColor(Color.black); g.fillRect(185, 405, 140, 30); g.setColor(Color.white); g.drawString("Credits", 222, 425); g.setColor(Color.white); g.fillRect(posx_highscores, posy_highscores, 150, 40); g.setColor(Color.black); g.fillRect(185, 455, 140, 30); g.setColor(Color.white); g.drawString("High Scores", 205, 475); g.setFont(new Font("Arial", Font.BOLD, 15)); g.setColor(Color.white); g.drawString("Instructions:", 218, 520); g.setFont(new Font("Arial", Font.PLAIN, 15)); g.drawString("Scroll to the appropriate button and hit [Enter] to continue.", 70, 535); g.drawString("Press [Esc] to return back to Main Menu.", 130, 550); }
public void paint(Graphics g) { g.setFont(new Font("Arial", Font.BOLD, 28)); drawTree(g, 10, getWidth(), number, 0, 50); }