/** Affichage du logo */ protected void drawLogo(Graphics g) { int x = 5; int y = 2; g.setColor(getBackground()); g.fillRect(0, 0, W, H); // Remplissage fillBG(g, x, y, Color.white); // Dessin drawGrid( g, x, y, !isAvailable() ? Aladin.MYGRAY : isActive() ? Aladin.GREEN : isMouseIn() ? Color.blue : Color.black); // Label g.setColor(isAvailable() ? Color.black : Aladin.MYGRAY); g.setFont(Aladin.SPLAIN); g.drawString(LABEL, W / 2 - g.getFontMetrics().stringWidth(LABEL) / 2, H - 2); }
// draws the button, based on the type of button (ImageIcon, Image, or String) public void draw(Graphics g) { if (visible) { // if its image/imageicon, draw it g.setColor(new Color(50, 200, 50)); g.fillRect(x - 1, y - 1, width + 2, height + 2); if (mode.equals("Image") || mode.equals("ImageIcon")) { if (enabled) { g.drawImage(image, x, y, null); } else { g.drawImage(BWimage, x, y, null); } // if its string, draw the string } else { g.setFont(new Font("Arial", Font.PLAIN, 20)); if (enabled) { g.setColor(Color.black); g.drawString(message, x + 20, y + 20); } else { g.setColor(new Color(255, 255, 255)); g.fillRect(x - 1, y - 1, width + 2, height + 2); g.setColor(Color.black); g.drawString(message, x + 20, y + 20); } } } }
/** * Function: drawNode Pre: Takes a graphics object g to draw on. Also takes two ints (x_size, * y_size) defining the screen size Also takes a node radius r Post: Prints out this node to the * screen appropriately */ public void drawNode(Graphics g, int x_size, int y_size, int r) { // Don't print nodes that aren't activated if (!activated) return; // First, get some stats based on the Graphics area size // In particular, the size of the Node int px = (int) (x_size * x) - r; // X & Y positions int py = (int) (y_size * y) - r; // Set the font to appropriate no matter what // int sizor; //The size for the text, based on radius g.setFont(new Font("Serif", Font.BOLD, r)); // Find the color for the text, it's used often... we'll do this later now // String textcol = getOtherTextColor(color); MOOF! UPDATE THIS LATER! // Make sure the color is correct no matter what... adjust also later! // Node insides... get this color correct later, moof! g.setColor(getMyJavaColor()); // g.setColor(Color.white); g.fillOval(px, py, r * 2, r * 2); // Node border g.setColor(getJavaColor(getOtherNodeColor(color))); g.drawOval(px, py, r * 2, r * 2); // Text inside... set up to be centered py = py + r + (int) (g.getFontMetrics().getAscent() / 2.2); px = px + r - (g.getFontMetrics().stringWidth("" + cindex) / 2); g.drawString("" + cindex, px, py); }
public void paint(Graphics g) { g.setColor(this.getBackground()); g.fillRect(0, 0, this.width, this.height); g.setColor(this.getForeground()); g.drawImage(this.imLogo, 10, 40, this); g.setFont(this.fontTitle); g.drawString(this.appName, 70, 65); g.setFont(this.fontText); int startY = 130; int l = 6; for (int i = 0; i < textLines.length; ++i) { g.drawString(this.textLines[i], 10, startY); startY += 20; } if (str != null) g.drawString(str, 10, startY); g.drawImage(this.imHelp, 50, startY + 30, this); }
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 drawBox(Graphics g, int x, int y, String str, Color fg, Color bg, Font font) { g.setColor(bg); g.fillRect(x, y, horizSpace, vertSpace); g.setColor(Color.black); g.drawRect(x, y, horizSpace, vertSpace); g.setColor(fg); g.setFont(font); g.drawString(str, x + 2, y + vertSpace - 4); }
/** This internal method begins a new page and prints the header. */ protected void newpage() { page = job.getGraphics(); // Begin the new page linenum = 0; charnum = 0; // Reset line and char number pagenum++; // Increment page number page.setFont(headerfont); // Set the header font. page.drawString(jobname, x0, headery); // Print job name left justified String s = "- " + pagenum + " -"; // Print the page number centered. int w = headermetrics.stringWidth(s); page.drawString(s, x0 + (this.width - w) / 2, headery); w = headermetrics.stringWidth(time); // Print date right justified page.drawString(time, x0 + width - w, headery); // Draw a line beneath the header int y = headery + headermetrics.getDescent() + 1; page.drawLine(x0, y, x0 + width, y); // Set the basic monospaced font for the rest of the page. page.setFont(font); }
public void paint(Graphics g) { if (comp != null) { width = comp.getWidth() / 6; height = comp.getHeight() * 2 / 3; } g.setColor(bgColor); g.fillRect(x, y, width, height); g.setColor(fgColor); g.setFont(font); g.drawString(strTray, x / 2 + width / 2, y + height + 10); super.paint(g); }
/** * Set the font style. The argument should be one of the font style constants defined by the * java.awt.Font class. All subsequent output will be in that style. This method relies on all * styles of the Monospaced font having the same metrics. */ public void setFontStyle(int style) { synchronized (this.lock) { // Try to set a new font, but restore current one if it fails Font current = font; try { font = new Font("Monospaced", style, fontsize); } catch (Exception e) { font = current; } // If a page is pending, set the new font. Otherwise newpage() will. if (page != null) page.setFont(font); } }
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 } }
private final void showpercent(String s, int i, int j) { Graphics g = getGraphics(); Font font = new Font("Helvetica", 1, 13); FontMetrics fontmetrics = getFontMetrics(font); Font font1 = new Font("Helvetica", 0, 13); FontMetrics fontmetrics1 = getFontMetrics(font1); if (all || !img && mt.checkAll(true)) { all = false; if (img || mt.checkAll(true)) { g.drawImage(loading, 0, 0, this); img = true; } else { g.setColor(Color.black); g.fillRect(0, 0, 512, 344); } g.setColor(Color.white); g.setFont(font); String s1 = "RuneScape has been updated!"; g.drawString(s1, 256 - fontmetrics.stringWidth(s1) / 2, 125); s1 = "Please wait - Fetching new files..."; g.drawString(s1, 256 - fontmetrics.stringWidth(s1) / 2, 140); g.setFont(font1); s1 = "This may take a few minutes, but only"; g.drawString(s1, 256 - fontmetrics1.stringWidth(s1) / 2, 165); s1 = "needs to be done when the game is updated."; g.drawString(s1, 256 - fontmetrics1.stringWidth(s1) / 2, 180); } Color color = new Color(140, 17, 17); g.setColor(color); g.drawRect(104, 190, 304, 34); g.fillRect(106, 192, j * 3, 30); g.setColor(Color.black); g.fillRect(106 + j * 3, 192, 300 - j * 3, 30); String s2 = "Loading " + s + " - " + i + "%"; g.setFont(font); g.setColor(Color.white); g.drawString(s2, 256 - fontmetrics.stringWidth(s2) / 2, 212); }
public void update(Graphics g) { Dimension d = getSize(); int rad, angles[] = {180, 0}; Point center; if ((offscreen_ == null) || (d.width != offscreensize_.width) || (d.height != offscreensize_.height)) { offscreen_ = createImage(d.width, d.height); offscreensize_ = new Dimension(d.width, d.height); offgraphics_ = offscreen_.getGraphics(); offgraphics_.setFont(getFont()); // g.setColor (Color.lightGray); // g.draw3DRect (0, 0, d.width - 1, d.height - 1, true); // g.draw3DRect (1, 1, d.width - 3, d.height - 3, true); // g.draw3DRect (2, 2, d.width - 5, d.height - 5, true); } offgraphics_.setColor(getBackground()); offgraphics_.fillRect(0, 0, d.width, d.height); offgraphics_.setColor(BLUE); // Calculate from the dimensions, the largest square. center = new Point(d.width / 2, d.height / 2); rad = ((center.x < center.y) ? center.x : center.y); // Draw a circle of blue offgraphics_.fillOval(center.x - rad, center.y - rad, 2 * rad, 2 * rad); // Roll the horizon based on the roll angle if (roll_ != 0) roll_horizon(rad, angles); // Pitch the horizon based on the pitch angle if (pitch_ != 0) pitch_horizon(rad, angles); // Draw the resulting terrain draw_horizon(rad, center, angles); // Draw the plotted Image. g.drawImage(offscreen_, 0, 0, null); }
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); }
private static void drawBox( String str, Rectangle r, Color fillColor, Color textColor, Graphics g) { g.setColor(fillColor); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(Color.black); g.drawRect(r.x, r.y, r.width, r.height); int xbase = r.x; int ybase = r.y; int thisBoxHeight = r.height; g.drawLine( xbase - TDHelper.minBoxWidth / 2, ybase + thisBoxHeight / 2, xbase, ybase + thisBoxHeight / 2); g.setFont(ourFont); if (str != null) { g.setColor(textColor); g.drawString(str, xbase + 3, ybase + thisBoxHeight - TDHelper.descenderPixels); } }
// ------------------------------------------------------------------------------------------------------------------------------------ // 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 static void drawValueBar( int x, int y, String labelhead, double value, double percentage, int colorindex, Graphics g) { g.setColor(GetColor(colorindex)); g.drawRect(x, y, VALUE_BAR_WIDTH, VALUE_BAR_HEIGHT); int barwidth; if (percentage < 0.0) { // Unknown value barwidth = VALUE_BAR_WIDTH - 1; } else { barwidth = (int) ((VALUE_BAR_WIDTH - 1) * Math.min(1.0, percentage)); } // g.setColor(gradientColor(percentage)); g.fillRect(x + 1, y + 1, barwidth, VALUE_BAR_HEIGHT - 1); if (labelhead != null) { g.setFont(MainFrame.defaultFont); // g.setColor(MainFrame.labelColor); int off = 2; g.drawString(labelhead, x + VALUE_BAR_WIDTH + 2, y + VALUE_BAR_HEIGHT); // off += (labelhead.length()+1) * 4; // Just a guess String maxStr = new String("DateRate [/sec]:"); off += (int) ((maxStr.length() + 1) * 5.5); if (value < 0.0) { g.drawString("?", x + VALUE_BAR_WIDTH + off, y + VALUE_BAR_HEIGHT); } else { if (percentage < 0.0) { g.drawString(format(value), x + VALUE_BAR_WIDTH + off, y + VALUE_BAR_HEIGHT); } else { g.drawString( format(value) + " (" + format(percentage * 100) + "%)", x + VALUE_BAR_WIDTH + off, y + VALUE_BAR_HEIGHT); } } } }
private void drawStoreName(Graphics g) // PRE: g must be initialized. // POST: Draws the store name along with a rounded border at the top of the window. { int rectWidth; // The width of the drawing area. int rectHeight; // The height of the drawing area. String storeName; // The name of the store. Font font; // The font to be used. rectWidth = nameLocation[1].getScaledX() - nameLocation[0].getScaledX(); rectHeight = nameLocation[1].getScaledY() - nameLocation[0].getScaledY(); switch (store) // set message based on store value. { case 0: storeName = "Raneac's Crucible"; break; case 1: storeName = "The Iron Maiden"; break; case 2: storeName = "The Grand Bazaar"; break; default: storeName = "Miko's Wares"; } font = Drawing.getFont(storeName, rectWidth, rectHeight, FONTNAME, FONTSTYLE); g.setFont(font); g.setColor(Color.WHITE); g.drawString( storeName, nameLocation[0].getScaledX(), (int) (nameLocation[1].getScaledY() * .98)); Drawing.drawRoundedRect(g, nameLocation, Color.WHITE); }
// Draws anything that is on the screen by using a Graphics object and using methods such as // drawImage and drawString public void paintGame() { // Creates a Graphics object Graphics g = bs.getDrawGraphics(); // draws background g.drawImage(gridBackground, 0, 0, this); // draws scoreboard g.drawImage(scoreBoard, 650, 0, this); // Switch statement used for drawing the information of the players on the right side. switch (numOfPlayers) { case 4: g.setColor(Color.RED); g.setFont(new Font("SansSerif", Font.BOLD, 35)); g.drawString(player[3].getName() + ":", 675, 430); if (winPlayer == 3) { g.drawImage(miscBombermanSprite[7], 670, 443, this); } else if (player[3].getHealth() > 0) { g.drawImage(bombermanSprite[12], 670, 443, this); } else { g.drawImage(miscBombermanSprite[6], 670, 443, this); } // Loops to draw the hearts for (int i = 0; i < player[3].getHealth(); i++) { g.drawImage(heart, 720 + (i * 40), 455, this); } case 3: g.setColor(Color.GREEN); g.setFont(new Font("SansSerif", Font.BOLD, 35)); g.drawString(player[2].getName() + ":", 675, 320); if (winPlayer == 2) { g.drawImage(miscBombermanSprite[5], 670, 333, this); } else if (player[2].getHealth() > 0) { g.drawImage(bombermanSprite[8], 670, 333, this); } else { g.drawImage(miscBombermanSprite[4], 670, 333, this); } // Loops to draw the hearts for (int i = 0; i < player[2].getHealth(); i++) { g.drawImage(heart, 720 + (i * 40), 345, this); } case 2: g.setColor(Color.BLACK); g.setFont(new Font("SansSerif", Font.BOLD, 35)); g.drawString(player[1].getName() + ":", 675, 210); if (winPlayer == 1) { g.drawImage(miscBombermanSprite[3], 670, 223, this); } else if (player[1].getHealth() > 0) { g.drawImage(bombermanSprite[4], 670, 223, this); } else { g.drawImage(miscBombermanSprite[2], 670, 223, this); } // Loops to draw the hearts for (int i = 0; i < player[1].getHealth(); i++) { g.drawImage(heart, 720 + (i * 40), 235, this); } case 1: g.setColor(Color.WHITE); g.setFont(new Font("SansSerif", Font.BOLD, 35)); g.drawString(player[0].getName() + ":", 675, 100); if (winPlayer == 0) { g.drawImage(miscBombermanSprite[1], 670, 113, this); } else if (player[0].getHealth() > 0) { g.drawImage(bombermanSprite[0], 670, 113, this); } else { g.drawImage(miscBombermanSprite[0], 670, 113, this); } // Loops to draw the hearts for (int i = 0; i < player[0].getHealth(); i++) { g.drawImage(heart, 720 + (i * 40), 125, this); } // Breaks from the switch statement break; } // Draws the map for (int i = 0; i < 11; i++) { for (int j = 0; j < 11; j++) { g.drawImage(tileImage[grid[i][j]], i * 50 + 50, j * 50 + 50, this); } } // Draws the bomberman sprites switch (numOfPlayers) { case 4: if (player[3].getHealth() > 0) g.drawImage( bombermanSprite[12 + player[3].getDirection()], player[3].getXPos(), player[3].getYPos(), this); case 3: if (player[2].getHealth() > 0) g.drawImage( bombermanSprite[8 + player[2].getDirection()], player[2].getXPos(), player[2].getYPos(), this); case 2: if (player[1].getHealth() > 0) g.drawImage( bombermanSprite[4 + player[1].getDirection()], player[1].getXPos(), player[1].getYPos(), this); case 1: if (player[0].getHealth() > 0) g.drawImage( bombermanSprite[0 + player[0].getDirection()], player[0].getXPos(), player[0].getYPos(), this); break; } // Draws that a player has won if winPlayer ranges from 1 to 3 if (winPlayer >= 0 && winPlayer != 5) { g.setColor(Color.ORANGE); g.setFont(new Font("SansSerif", Font.BOLD, 50)); g.drawString("Player " + (winPlayer + 1) + " WINS!", 150, 290); } // Draws that there is a draw if winPlayer is -1 else if (winPlayer == -1) { g.setColor(Color.ORANGE); g.setFont(new Font("SansSerif", Font.BOLD, 50)); g.drawString("DRAW", 250, 290); } // show new buffer bs.show(); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; RenderingHints rh = g2d.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); // Background. D = this.getSize(); g.setColor(backgroundColor); g.fillRect(0, 0, D.width, D.height); Graphics2D g2 = (Graphics2D) g; g2.setStroke(lineStroke); // Axes, bounding box. g.setColor(Color.gray); g.drawLine(inset, D.height - inset, D.width - inset, D.height - inset); g.drawLine(D.width - inset, inset, D.width - inset, D.height - inset); g.drawLine(inset, inset, inset, D.height - inset); g.drawLine(inset, inset, D.width - inset, inset); double xDelta = (maxX - minX) / numIntervals; // X-ticks and labels. for (int i = 1; i <= numIntervals; i++) { double xTickd = i * xDelta; int xTick = (int) (xTickd / (maxX - minX) * (D.width - 2 * inset)); g.drawLine(inset + xTick, D.height - inset - 5, inset + xTick, D.height - inset + 5); double x = minX + i * xDelta; g.drawString(df.format(x), xTick + inset - 5, D.height - inset + 20); } // Y-ticks double yDelta = (maxY - minY) / numIntervals; for (int i = 0; i < numIntervals; i++) { int yTick = (i + 1) * (int) ((D.height - 2 * inset) / (double) numIntervals); g.drawLine(inset - 5, D.height - yTick - inset, inset + 5, D.height - yTick - inset); double y = minY + (i + 1) * yDelta; g.drawString(df.format(y), 1, D.height - yTick - inset); } // Zoom+move Font savedFont = g.getFont(); g.setFont(plusFont); g.drawString("+", D.width - 25, 20); g.setFont(minusFont); g.drawString("-", D.width - 25, 50); drawArrow(g2d, D.width - 70, 20, D.width - 70, 0, 1.0f, lineStroke); // Up drawArrow(g2d, D.width - 70, 30, D.width - 70, 50, 1.0f, lineStroke); // Down drawArrow(g2d, D.width - 65, 25, D.width - 45, 25, 1.0f, lineStroke); // Right drawArrow(g2d, D.width - 75, 25, D.width - 95, 25, 1.0f, lineStroke); // Left g.setFont(savedFont); // See if standard axes are in the middle. g.setColor(Color.gray); if ((minX < 0) && (maxX > 0) && (drawMiddleAxes)) { // Draw y-axis int x = (int) ((0 - minX) / (maxX - minX) * (D.width - 2 * inset)); g.drawLine(inset + x, D.height - inset, inset + x, inset); } if ((minY < 0) && (maxY > 0) && (drawMiddleAxes)) { // Draw x-axis int y = (int) ((0 - minY) / (maxY - minY) * (D.height - 2.0 * inset)); g.drawLine(inset, D.height - y - inset, D.width - inset, D.height - y - inset); } // Draw the objects. drawObjects(g, points, lines, ovals, rectangles, images, labels, eqnLines); if (animationMode) { drawObjects(g, animPoints, animLines, animOvals, animRectangles, null, labels, eqnLines); // No images in animation mode. } drawScribbles(g); }
public void paint(Graphics g) { path = findOptimizedPath(srcID, dstID, type); /// Create the drawing board Dimension d = getSize(); g.setColor(Color.white); g.fillRect(1, 1, d.width - 2, d.height - 2); g.setColor(Color.black); g.drawRect(1, 1, d.width - 2, d.height - 2); g.setFont(serifFont); /// Draw the whole network, including all routers with /// delay and flow level, sources and destinations. int numR = 1; int w = 95; int h = d.height / 5; int pos = -1; for (int i = 0; i < 3; i++) { g.drawOval(w, h + 100 * i, 40, 40); g.drawString("S" + String.valueOf(i + 1), w + 13, h + 100 * i - 5); } for (int i = 0; i < 3; i++) { pos++; Router temp = statMux.getRouter(pos); g.drawOval(w + 110, h + 100 * i, 40, 40); g.drawString("R" + String.valueOf(numR++), w + 123, h + 100 * i - 5); g.drawString( String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()), w + 125, h + 100 * i + 15); g.drawString(String.valueOf(temp.getFlowLevel()), w + 125, h + 100 * i + 35); } h = d.height / 11; for (int i = 0; i < 4; i++) { pos++; Router temp = statMux.getRouter(pos); g.drawOval(w + 210, h + 100 * i, 40, 40); g.drawString("R" + String.valueOf(numR++), w + 223, h + 100 * i - 5); g.drawString( String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()), w + 225, h + 100 * i + 15); g.drawString(String.valueOf(temp.getFlowLevel()), w + 225, h + 100 * i + 35); } h = 20; for (int i = 0; i < 6; i++) { pos++; Router temp = statMux.getRouter(pos); g.drawOval(w + 310, h + 80 * i, 40, 40); g.drawString("R" + String.valueOf(numR++), w + 320, h + 80 * i - 5); g.drawString( String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()), w + 325, h + 80 * i + 15); g.drawString(String.valueOf(temp.getFlowLevel()), w + 325, h + 80 * i + 35); } for (int i = 0; i < 4; i++) { g.drawOval(w + 410, d.height / 11 + 100 * i, 40, 40); g.drawString("D" + String.valueOf(i + 1), w + 423, d.height / 11 + 100 * i - 5); } g.setColor(Color.black); int[][] connection = statMux.getConnections(); /// Check buffer for connections at each step and draw links at layer1 for (int i = 0; i < connection[path[0] - 1].length; i++) { int temp = connection[path[0] - 1][i] - 3; g.drawLine(w + 40, (path[0]) * d.height / 5 + 20, w + 110, temp * d.height / 5 + 20); } /// Check buffer for connections at each step and draw links at layer2 for (int i = 0; i < connection[path[1] - 1].length; i++) { int temp = connection[path[1] - 1][i] - 7; g.drawLine( w + 150, (path[1] - 3) * d.height / 5 + 20, w + 210, (d.height / 11) + 100 * temp + 20); } /// Check buffer for connections at each step and draw links at layer3 for (int i = 0; i < connection[path[2] - 1].length; i++) { int temp = connection[path[2] - 1][i] - 11; g.drawLine(w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * temp + 40); } /// Draw optimized path for packets traveling between source /// and destination h = d.height / 5; Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(2)); g2.setColor(Color.red); g2.drawLine(w + 40, h * (path[0]) + 20, w + 110, h * (path[1] - 3) + 20); g2.drawLine( w + 150, h * (path[1] - 3) + 20, w + 210, (d.height / 11) + 100 * (path[2] - 7) + 20); g2.drawLine( w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * (path[3] - 11) + 40); g2.drawLine( w + 350, 80 * (path[3] - 11) + 40, w + 410, (d.height / 11) + 100 * (path[4] - 17) + 20); /// Calculate and display loss, delay, and throughput delayTime = getDelay(path, type); throughPut = getThroughput(path); int numPackLost = getLossRate(numTransfer); lossRate = numPackLost / 100000.0 + 0.0005 * delayTime; delayVal.setText(String.format("%.2f", delayTime)); throuVal.setText(String.valueOf(throughPut)); lossVal.setText(String.format("%.4f", lossRate)); }
static void paintShadowTitle( Graphics g, String title, int x, int y, Color frente, Color shadow, int desp, int tipo, int orientation) { // Si hay que rotar la fuente, se rota Font f = g.getFont(); if (orientation == SwingConstants.VERTICAL) { AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); f = f.deriveFont(rotate); } // Si hay que pintar sombra, se hacen un monton de cosas if (shadow != null) { int matrix = (tipo == THIN ? MATRIX_THIN : MATRIX_FAT); Rectangle2D rect = g.getFontMetrics().getStringBounds(title, g); int w, h; if (orientation == SwingConstants.HORIZONTAL) { w = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde h = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP } else { h = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde w = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP } // La sombra del titulo BufferedImage iTitulo = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); BufferedImage iSombra = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = iTitulo.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setFont(f); g2.setColor(shadow); g2.drawString(title, 3 * matrix, 3 * matrix); // La pintamos en el centro ConvolveOp cop = new ConvolveOp((tipo == THIN ? kernelThin : kernelFat), ConvolveOp.EDGE_NO_OP, null); cop.filter(iTitulo, iSombra); // A ditorsionar // Por fin, pintamos el jodio titulo g.drawImage( iSombra, x - 3 * matrix + desp, // Lo llevamos a la posicion original y le sumamos 1 y - 3 * matrix + desp, // para que la sombra quede pelin desplazada null); } // Si hay que pintar el frente, se pinta if (frente != null) { g.setFont(f); g.setColor(frente); g.drawString(title, x, y); } }
// ************************************************************************************** // Method: paint // Description: Display an image stored in a 2D array. Overrides the paint method // inherited from Frame (via Container). Allows for showing an image // one time or continuously (for example, if it is being constantly // updated by a digital camera. // Parameters: g - the graphics object // Returns: nothing // Calls: setColorValues for an ImageClass object // setGrayValues for an ImageClass object // referenceColorArrayData // referenceGrayArrayData // plus various Java graphics routines public void paint(Graphics g) { int row, column, pixel; Color color = new Color(0); int i, a = 0, b = 0; while (a == b) { if (imageType == 1) { for (row = 0; row < imageHeight; row++) { for (column = 0; column < imageWidth; column++) { color = new Color( redPixels[row][column], greenPixels[row][column], bluePixels[row][column]); g.setColor(color); g.drawLine( column + windowSideOffset, row + windowHeaderOffset, column + windowSideOffset, row + windowHeaderOffset); } } } else if ((imageType == 2) || (imageType == 3)) { for (row = 0; row < imageHeight; row++) { for (column = 0; column < imageWidth; column++) { pixel = pixels[row][column]; color = new Color(pixel, pixel, pixel); g.setColor(color); g.drawLine( column + windowSideOffset, row + windowHeaderOffset, column + windowSideOffset, row + windowHeaderOffset); } } } g.setColor(Color.white); Font f = new Font("sansserif", Font.BOLD, 12); g.setFont(f); for (i = 0; i < textLineCount; i++) g.drawString( text[i], textPosition[i][1] + windowSideOffset, textPosition[i][0] + windowHeaderOffset); if (showOnce) b++; // exit else { if (sourceImage != null) { sourceImage.getRawPixelData(); if (imageType == 1) { sourceImage.setColorValues(); referenceColorArrayData( sourceImage.redPixels, sourceImage.greenPixels, sourceImage.bluePixels); } else { sourceImage.setGrayValues(); referenceGrayArrayData(sourceImage.pixels); } } // else //removed to allow for continuous display based on updates to this object other // than from // b++; //an ImageClass object } } }
@Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.black); g.fillRect(0, 0, getWidth(), getHeight()); for (Integer id : planetNames.keySet()) { String name = planetNames.get(id); Point p = planetCoordinates.get(id); PartialPlanetBlock planet = getPlanet(id, -2); g.setColor(Color.gray); int rad = 3; if (planet != null) { rad = 6; if (animatorFrame) { Color col = colors.get(planet.owner); if (col == null) col = Color.gray; g.setColor(col); } else { if (planet.owner == settings.playerNr) g.setColor(Color.green); else if (colorize.isSelected() && colors.get(planet.owner) != null) g.setColor(colors.get(planet.owner)); else if (friends.contains(planet.owner)) g.setColor(Color.YELLOW); else if (planet.owner >= 0) g.setColor(Color.red); else rad = 3; } } int x = convertX(p.x); int y = convertY(p.y); double virtualWidth = getWidth() * zoom / 100; double virtualHeight = getHeight() * zoom / 100; int xOffset = (int) (getWidth() - virtualWidth) / 2; int yOffset = (int) (getHeight() - virtualHeight) / 2; x = (int) (xOffset + x * zoom / 100.0 - mariginX * zoom / 100.0); y = (int) (yOffset + y * zoom / 100.0 - mariginY * zoom / 100.0); g.fillOval(x - rad / 2, y - rad / 2, rad, rad); if (names.isSelected()) { g.setFont(g.getFont().deriveFont((float) 10)); g.setColor(Color.gray); int stringWidth = g.getFontMetrics().stringWidth(name); g.drawString(name, x - stringWidth / 2, y + 12); } if (colorize.isSelected() || animatorFrame) { int yy = 20; g.setFont(g.getFont().deriveFont((float) 12)); for (PlayerBlock pb : GalaxyViewer.this.p.players) { if (pb == null) continue; Color col = colors.get(pb.playerNumber); if (animatorFrame && col != null) ; // Ok else if (pb.playerNumber == settings.playerNr) col = Color.green; else if (col == null) col = Color.red; g.setColor(col); String n = new String(pb.nameBytes); // Does not work n = "Player " + (pb.playerNumber + 1); g.drawString(n, 5, yy); // System.out.print(pb.playerNumber+": "); // for (int t = 0; t < pb.nameBytes.length; t++){ // System.out.print((pb.nameBytes[t]&0xff)+" "); // System.out.print((pb.nameBytes[t])+" "); // } // System.out.println(); yy += 14; } } } }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); int width = getWidth() - rightMargin - leftMargin - 10; int height = getHeight() - topMargin - bottomMargin; if (width <= 0 || height <= 0) { // not enough room to paint anything return; } Color oldColor = g.getColor(); Font oldFont = g.getFont(); Color fg = getForeground(); Color bg = getBackground(); boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200); ((Graphics2D) g) .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (smallFont == null) { smallFont = oldFont.deriveFont(9.0F); } r.x = leftMargin - 5; r.y = topMargin - 8; r.width = getWidth() - leftMargin - rightMargin; r.height = getHeight() - topMargin - bottomMargin + 16; if (border == null) { // By setting colors here, we avoid recalculating them // over and over. border = new BevelBorder( BevelBorder.LOWERED, getBackground().brighter().brighter(), getBackground().brighter(), getBackground().darker().darker(), getBackground().darker()); } border.paintBorder(this, g, r.x, r.y, r.width, r.height); // Fill background color g.setColor(bgColor); g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4); g.setColor(oldColor); long tMin = Long.MAX_VALUE; long tMax = Long.MIN_VALUE; long vMin = Long.MAX_VALUE; long vMax = 1; int w = getWidth() - rightMargin - leftMargin - 10; int h = getHeight() - topMargin - bottomMargin; if (times.size > 1) { tMin = Math.min(tMin, times.time(0)); tMax = Math.max(tMax, times.time(times.size - 1)); } long viewRangeMS; if (viewRange > 0) { viewRangeMS = viewRange * MINUTE; } else { // Display full time range, but no less than a minute viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE); } // Calculate min/max values for (Sequence seq : seqs) { if (seq.size > 0) { for (int i = 0; i < seq.size; i++) { if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) { long val = seq.value(i); if (val > Long.MIN_VALUE) { vMax = Math.max(vMax, val); vMin = Math.min(vMin, val); } } } } else { vMin = 0L; } if (unit == Unit.BYTES || !seq.isPlotted) { // We'll scale only to the first (main) value set. // TODO: Use a separate property for this. break; } } // Normalize scale vMax = normalizeMax(vMax); if (vMin > 0) { if (vMax / vMin > 4) { vMin = 0; } else { vMin = normalizeMin(vMin); } } g.setColor(fg); // Axes // Draw vertical axis int x = leftMargin - 18; int y = topMargin; FontMetrics fm = g.getFontMetrics(); g.drawLine(x, y, x, y + h); int n = 5; if (("" + vMax).startsWith("2")) { n = 4; } else if (("" + vMax).startsWith("3")) { n = 6; } else if (("" + vMax).startsWith("4")) { n = 4; } else if (("" + vMax).startsWith("6")) { n = 6; } else if (("" + vMax).startsWith("7")) { n = 7; } else if (("" + vMax).startsWith("8")) { n = 8; } else if (("" + vMax).startsWith("9")) { n = 3; } // Ticks ArrayList<Long> tickValues = new ArrayList<Long>(); tickValues.add(vMin); for (int i = 0; i < n; i++) { long v = i * vMax / n; if (v > vMin) { tickValues.add(v); } } tickValues.add(vMax); n = tickValues.size(); String[] tickStrings = new String[n]; for (int i = 0; i < n; i++) { long v = tickValues.get(i); tickStrings[i] = getSizeString(v, vMax); } // Trim trailing decimal zeroes. if (decimals > 0) { boolean trimLast = true; boolean removedDecimalPoint = false; do { for (String str : tickStrings) { if (!(str.endsWith("0") || str.endsWith("."))) { trimLast = false; break; } } if (trimLast) { if (tickStrings[0].endsWith(".")) { removedDecimalPoint = true; } for (int i = 0; i < n; i++) { String str = tickStrings[i]; tickStrings[i] = str.substring(0, str.length() - 1); } } } while (trimLast && !removedDecimalPoint); } // Draw ticks int lastY = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { long v = tickValues.get(i); y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin)); g.drawLine(x - 2, y, x + 2, y); String s = tickStrings[i]; if (unit == Unit.PERCENT) { s += "%"; } int sx = x - 6 - fm.stringWidth(s); if (y < lastY - 13) { if (checkLeftMargin(sx)) { // Wait for next repaint return; } g.drawString(s, sx, y + 4); } // Draw horizontal grid line g.setColor(Color.lightGray); g.drawLine(r.x + 4, y, r.x + r.width - 4, y); g.setColor(fg); lastY = y; } // Draw horizontal axis x = leftMargin; y = topMargin + h + 15; g.drawLine(x, y, x + w, y); long t1 = tMax; if (t1 <= 0L) { // No data yet, so draw current time t1 = System.currentTimeMillis(); } long tz = timeDF.getTimeZone().getOffset(t1); long tickInterval = calculateTickInterval(w, 40, viewRangeMS); if (tickInterval > 3 * HOUR) { tickInterval = calculateTickInterval(w, 80, viewRangeMS); } long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval; while (t0 < viewRangeMS) { x = leftMargin + (int) (w * t0 / viewRangeMS); g.drawLine(x, y - 2, x, y + 2); long t = t1 - viewRangeMS + t0; String str = formatClockTime(t); g.drawString(str, x, y + 16); // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) { if ((t + tz) % (1 * DAY) == 0) { str = formatDate(t); g.drawString(str, x, y + 27); } // Draw vertical grid line g.setColor(Color.lightGray); g.drawLine(x, topMargin, x, topMargin + h); g.setColor(fg); t0 += tickInterval; } // Plot values int start = 0; int nValues = 0; int nLists = seqs.size(); if (nLists > 0) { nValues = seqs.get(0).size; } if (nValues == 0) { g.setColor(oldColor); return; } else { Sequence seq = seqs.get(0); // Find starting point for (int p = 0; p < seq.size; p++) { if (times.time(p) >= tMax - viewRangeMS) { start = p; break; } } } // Optimization: collapse plot of more than four values per pixel int pointsPerPixel = (nValues - start) / w; if (pointsPerPixel < 4) { pointsPerPixel = 1; } // Draw graphs // Loop backwards over sequences because the first needs to be painted on top for (int i = nLists - 1; i >= 0; i--) { int x0 = leftMargin; int y0 = topMargin + h + 1; Sequence seq = seqs.get(i); if (seq.isPlotted && seq.size > 0) { // Paint twice, with white and with color for (int pass = 0; pass < 2; pass++) { g.setColor((pass == 0) ? Color.white : seq.color); int x1 = -1; long v1 = -1; for (int p = start; p < nValues; p += pointsPerPixel) { // Make sure we get the last value if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) { p = nValues - 1; } int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS); long v2 = seq.value(p); if (v2 >= vMin && v2 <= vMax) { int y2 = (int) (h * (v2 - vMin) / (vMax - vMin)); if (x1 >= 0 && v1 >= vMin && v1 <= vMax) { int y1 = (int) (h * (v1 - vMin) / (vMax - vMin)); if (y1 == y2) { // fillrect is much faster g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1); } else { Graphics2D g2d = (Graphics2D) g; Stroke oldStroke = null; if (seq.transitionStroke != null) { oldStroke = g2d.getStroke(); g2d.setStroke(seq.transitionStroke); } g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass); if (oldStroke != null) { g2d.setStroke(oldStroke); } } } } x1 = x2; v1 = v2; } } // Current value long v = seq.value(seq.size - 1); if (v >= vMin && v <= vMax) { if (bgIsLight) { g.setColor(seq.color); } else { g.setColor(fg); } x = r.x + r.width + 2; y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin)); // a small triangle/arrow g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3); } g.setColor(fg); } } int[] valueStringSlots = new int[nLists]; for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1; for (int i = 0; i < nLists; i++) { Sequence seq = seqs.get(i); if (seq.isPlotted && seq.size > 0) { // Draw current value // TODO: collapse values if pointsPerPixel >= 4 long v = seq.value(seq.size - 1); if (v >= vMin && v <= vMax) { x = r.x + r.width + 2; y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin)); int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i); g.setFont(smallFont); if (bgIsLight) { g.setColor(seq.color); } else { g.setColor(fg); } String curValue = getFormattedValue(v, true); if (unit == Unit.PERCENT) { curValue += "%"; } int valWidth = fm.stringWidth(curValue); String legend = (displayLegend ? seq.name : ""); int legendWidth = fm.stringWidth(legend); if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) { // Wait for next repaint return; } g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10)); g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3)); // Maybe draw a short line to value if (y2 > y + 3) { g.drawLine(x + 9, y + 2, x + 14, y2); } else if (y2 < y - 3) { g.drawLine(x + 9, y - 2, x + 14, y2); } } g.setFont(oldFont); g.setColor(fg); } } g.setColor(oldColor); }
public void paint(Graphics g) { g.setFont(inputFont); g.setColor(0xffffff); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(0x000000); int x = getCursorX(); int y = getCursorY(); translationX = caretLeft - (getWidth() - 5); // if(isUp) // { translationY = y * inputHeight - (getHeight() - 40); // } // else if(isDown) // { // translationY = y*inputHeight - (getHeight() - 40); // } // etc if (translationX > 0) { g.translate(-translationX, 0); } if (translationY > 0) { g.translate(0, -translationY); displayLines(g, y - linesOnScreen); } else { displayLines(g, 0); } if (caretBlinkOn && goToNextChar) { displayCursor(g); } if (translationX > 0) { g.translate(translationX, 0); } if (translationY > 0) { g.translate(0, translationY); } if (currentState == EditorState.Commands) { if (!goToNextChar) { displayCharacterMap(g); } else { displayCurrentCommand(g); } } else if (currentState == EditorState.Input) { if (!goToNextChar) { displayCharacterMap(g); } else if (isViewStatus) { displayStatus(g); } } if (isViewScrollBar) { displayScrollBar(g); } }
private void drawItem(Graphics g, int item, Item currentItem) { Font font; // The font to be used. int x1; // The first x coordinate of drawing area. int y1; // The first y coordinate of drawing area. int x2; // The second x coordinate of drawing area. int y2; // The second y coordinate of drawing area. int width; // Width of drawing area. int height; // Height of drawing area. int iconX; // x coordinate of the icon. int iconY; // y coordinate of the icon. int iconLength; // Length of the icon. int itemNameX; // The x coordinate of the item name. int itemNameLength; // The length of the item name. int itemPriceX; // The x coordinate of the item price. int itemPriceWidth; // The width of the item price. x1 = itemPositions[item][0].getScaledX(); x2 = itemPositions[item][1].getScaledX(); y1 = itemPositions[item][0].getScaledY(); y2 = itemPositions[item][1].getScaledY(); width = x2 - x1; height = y2 - y1; iconX = x1 + (int) (width * .01); iconY = y1 + (int) (height * .1); iconLength = (int) (height * .8); Drawing.drawImage(g, iconX, iconY, iconLength, iconLength, currentItem.getItemPath()); itemNameX = iconX + (int) (iconLength * 1.5); itemNameLength = (int) (width * 0.6); font = Drawing.getFont( currentItem.getItemName(), itemNameLength, (int) (iconLength * 0.8), FONTNAME, FONTSTYLE); g.setFont(font); g.setColor(Color.WHITE); g.drawString(currentItem.getItemName(), itemNameX, iconY + (int) (iconLength * 0.9)); itemPriceX = x1 + (int) (width * 0.8); itemPriceWidth = (int) (width * 0.15); font = Drawing.getFont( Integer.toString(currentItem.getPrice()), itemPriceWidth, iconLength, FONTNAME, FONTSTYLE); g.setFont(font); g.setColor(Color.WHITE); g.drawString( Integer.toString(currentItem.getPrice()), itemPriceX, iconY + (int) (iconLength * .9)); return; }
private void drawLayout(Graphics g) { g.setColor(Color.blue); g.drawRect(10, 10, width - 20, height - 20); g.setColor(Color.red.brighter()); Iterator f = players.iterator(); int lifeDisplayPosition = 0; while (f.hasNext()) { Player h = (Player) f.next(); if (h.isActive()) { lifeDisplayPosition++; String lifeInformation = "Player " + lifeDisplayPosition + ": "; for (int i = 0; i < h.getLives(); i++) { lifeInformation += "\u2606"; } g.drawString(lifeInformation, 20, lifeDisplayPosition * 40); } } borders[2] = width - 20; borders[3] = height - 20; Iterator i = players.iterator(); Player p; while (i.hasNext()) { p = (Player) i.next(); if (p.isActive() && !countdownF && (p.getX() < borders[0] || p.getY() < borders[1] || p.getX() > borders[2] || p.getY() > borders[3]) && (!p.getImmunity())) { p.decLives(width / 2, height / 2); p.setImmunity(true); } if (p.getLives() <= 0) { if (p instanceof MouseControlledPlayer) { MouseControlledPlayer m = (MouseControlledPlayer) p; removeMouseListener(m); removeMouseMotionListener(m); } else if (p instanceof KeyboardControlledPlayer) { KeyboardFocusManager.getCurrentKeyboardFocusManager() .removeKeyEventDispatcher((KeyboardControlledPlayer) p); } i.remove(); for (int h = 0; h < 4; h++) { if (deathLocation[h] == -1) { deathLocation[h] = p.getX(); deathLocation[h + 1] = p.getY(); break; } } } } if ((deathLocation[0] != -1) && (deathLocation[1] != -1)) { g.drawLine( deathLocation[0] - 15, deathLocation[1] - 15, deathLocation[0] + 15, deathLocation[1] + 15); g.drawLine( deathLocation[0] + 15, deathLocation[1] - 15, deathLocation[0] - 15, deathLocation[1] + 15); } if ((deathLocation[2] != -1) && (deathLocation[3] != -1)) { g.drawLine( deathLocation[2] - 15, deathLocation[3] - 15, deathLocation[2] + 15, deathLocation[3] + 15); g.drawLine( deathLocation[2] + 15, deathLocation[3] - 15, deathLocation[2] - 15, deathLocation[3] + 15); } if (!onePlayerAlive) { Font old = g.getFont(); g.setFont(new Font("monospaced", Font.BOLD, 20)); g.setColor(Color.red.darker()); g.drawString("GAME OVER", width / 2 - 40, height / 2); g.setFont(old); g.setColor(Color.WHITE); g.drawString("Score", width - 60, 25); g.drawString(String.valueOf(score), width - 60, 40); } }