// draw rectangles and Strings in different colors public void paintComponent(Graphics g) { super.paintComponent(g); // call superclass's paintComponent this.setBackground(Color.WHITE); // set new drawing color using integers g.setColor(new Color(255, 0, 0)); g.fillRect(15, 25, 100, 20); g.drawString("Current RGB: " + g.getColor(), 130, 40); // set new drawing color using floats g.setColor(new Color(0.50f, 0.75f, 0.0f)); g.fillRect(15, 50, 100, 20); g.drawString("Current RGB: " + g.getColor(), 130, 65); // set new drawing color using static Color objects g.setColor(Color.BLUE); g.fillRect(15, 75, 100, 20); g.drawString("Current RGB: " + g.getColor(), 130, 90); // display individual RGB values Color color = Color.MAGENTA; g.setColor(color); g.fillRect(15, 100, 100, 20); g.drawString( "RGB values: " + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue(), 130, 115); } // end method paintComponent
@Override public void draw(Graphics g, GamePanel parent) { int width = parent.getWidth() * 3 / 5; tgs.getOPS().draw(g, parent); g.setColor(new Color(255, 255, 255)); g.setFont(new Font("Rockwell", 0, 32)); g.fillRect(parent.getWidth() / 5, parent.getHeight() / 5, width, parent.getHeight() * 3 / 5); g.setColor(Color.BLACK); g.drawString( name, parent.getWidth() / 5 + width / 2 - g.getFontMetrics().stringWidth(name), parent.getHeight() / 5 + g.getFontMetrics().getHeight()); for (int i = 0; i < abilities.length; i++) { if (abilities[i] != null) { g.drawString( abilities[i], parent.getWidth() / 5, parent.getHeight() / 5 + g.getFontMetrics().getHeight() * (8 + i)); } } for (int i = 0; i < traits.length; i++) { if (i == currentIndex) { g.setColor(Color.RED); } else { g.setColor(Color.BLACK); } g.drawString( traits[i], parent.getWidth() / 5, parent.getHeight() / 5 + g.getFontMetrics().getHeight() * (2 + i)); } }
private void drawAxes(Graphics g) { g.drawLine(padding, height, width + padding, height); g.drawLine(padding, 0, padding, height); g.drawString("time", padding + width / 2, height + padding - 5); g.drawString("pop", 5, height / 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); } } } }
/** Overrides <code>Graphics.drawString</code>. */ public void drawString(AttributedCharacterIterator iterator, int x, int y) { DebugGraphicsInfo info = info(); if (debugLog()) { info().log(toShortString() + " Drawing text: \"" + iterator + "\" at: " + new Point(x, y)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawString(iterator, x, y); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.drawString(iterator, x, y); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.drawString(iterator, x, y); }
public static void drawString(JComponent c, Graphics g, String text, int x, int y) { Graphics2D g2D = (Graphics2D) g; Object savedRenderingHint = null; if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint()); } if (getJavaVersion() >= 1.6) { try { Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2"); Class classParams[] = { JComponent.class, Graphics.class, String.class, Integer.TYPE, Integer.TYPE }; Method m = swingUtilities2Class.getMethod("drawString", classParams); Object methodParams[] = {c, g, text, new Integer(x), new Integer(y)}; m.invoke(null, methodParams); } catch (Exception ex) { g.drawString(text, x, y); } } else { g.drawString(text, x, y); } if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint); } }
// how to use TextLayout#draw private void test1(Graphics g) { Graphics2D g2d = (Graphics2D) g; Font font = new Font("SansSerif", Font.PLAIN, 14); g2d.setFont(font); g.setColor(Color.WHITE); g.fillRect(0, 0, getWidth(), getHeight()); g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setColor(Color.BLACK); g.drawString("drawStringこんにちはabc文字列アンチエイリアスあり", 50, 50); // g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, // RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); g.setColor(Color.BLACK); g.drawString("drawStringこんにちはabc文字列アンチエイリアスなし", 50, 100); // g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, // RenderingHints.VALUE_TEXT_ANTIALIAS_ON); System.out.println(System.getProperty("awt.useSystemAAFontSettings")); // Java6 g.setColor(Color.BLACK); g.drawString("drawStringこんにちはabc文字列アンチエイリアスあり", 50, 150); // RenderingHints.VALUE_TEXT_ANTIALIAS_ONにすれば、TextLayoutの描画はにはアンチエイリアスがかかる。 FontRenderContext frc = g2d.getFontRenderContext(); TextLayout layout = new TextLayout("TextLayoutで文字列を描画", font, frc); // Rectangle2D bounds = layout.getBounds(); // bounds.setRect(50, 200, 50 + 400, 200 + 50); // g2d.draw(bounds); layout.draw(g2d, 50, 200); }
public void drawVictory(Graphics g) { g.setColor(new Color(0, 0, 0, 200)); g.fillRect(195, 220, 410, 110); g.setColor(new Color(255, 255, 255, 200)); g.fillRect(200, 225, 400, 100); g.setColor(new Color(0, 0, 0, 200)); g.setFont(new Font("Bell MT", Font.BOLD, 20)); FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20)); int hgt = metrics.getHeight(); String initialMessage; String followupMessage; if (nextWindow) { initialMessage = "You have gotten stronger."; followupMessage = player.getName() + " is now level " + player.getLevel() + "!"; } else { initialMessage = "You survived!"; followupMessage = "You and your allies gain " + totalExperience + " experience!"; } // Hgt = 26 int adv = metrics.stringWidth(initialMessage); g.drawString(initialMessage, getWidth() / 2 - adv / 2, 234 + hgt); adv = metrics.stringWidth(followupMessage); g.drawString(followupMessage, getWidth() / 2 - adv / 2, 269 + hgt); }
public void paintComponent(Graphics g) { if (name == "" && serialport == "") { Map<String, String> boardPreferences = Base.getBoardPreferences(); if (boardPreferences != null) setBoardName(boardPreferences.get("name")); else setBoardName("-"); setSerialPort(Preferences.get("serial.port")); } g.setColor(background); Dimension size = getSize(); g.fillRect(0, 0, size.width, size.height); g.setFont(font); g.setColor(foreground); int baseline = (high + g.getFontMetrics().getAscent()) / 2; g.drawString(text, 6, baseline); g.setColor(messageForeground); String tmp = name + " on " + serialport; Rectangle2D bounds = g.getFontMetrics().getStringBounds(tmp, null); g.drawString(tmp, size.width - (int) bounds.getWidth() - 20, baseline); if (Base.isMacOS()) { g.drawImage(resize, size.width - 20, 0, this); } }
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); } }
private void render() { // TODO Auto-generated method stub BufferStrategy bs = this.getBufferStrategy(); if (bs == null) { this.createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 0, WIDTH, HEIGHT); /// draw borders g.setColor(Color.ORANGE); g.drawRect(LIMIT_X1, LIMIT_Y1, LIMIT_X2, LIMIT_Y2); g.setColor(Color.WHITE); g.drawString("Gravity : ", WIDTH - 200, 20); g.drawString(Double.toString(GRAVITY), WIDTH - 100, 20); // render landingzone g.setColor(Color.GREEN); g.drawLine( (int) landingZone1.getX(), (int) landingZone1.getY(), (int) landingZone1.getX1(), (int) landingZone1.getY1()); handler.render(g); g.dispose(); bs.show(); }
public void paint(Graphics g) { if (gevonden == true) { g.drawString("De waarde is gevonden.", 20, 50); } else { g.drawString("De waarde is niet gevonden.", 20, 50); } }
/** renders this JComponent */ @Override public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // paint page super.paintComponent(g); // set label color if (this.getBackground().getBlue() + this.getBackground().getGreen() + this.getBackground().getRed() > 400) { g.setColor(Color.DARK_GRAY); } else { g.setColor(Color.LIGHT_GRAY); } // paint label at correct position if (fullview) { int xpos = (int) (this.getWidth() * 0.5 - g.getFontMetrics().getStringBounds(this.getName(), g).getCenterX()); g.drawString(this.getName(), xpos, getHeight() / 2); g.drawString(this.getName(), xpos, getHeight() / 4); g.drawString(this.getName(), xpos, getHeight() * 3 / 4); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.33F)); int imageX = (int) (this.getWidth() / 2 - IMAGE_WIDTH / 2 * Page.zoom); int imageWidth = (int) (IMAGE_WIDTH * Page.zoom); g.drawImage(this.getImage(), imageX, getHeight() / 2 + 5, imageWidth, imageWidth, null); g.drawImage(this.getImage(), imageX, getHeight() / 4 + 5, imageWidth, imageWidth, null); g.drawImage(this.getImage(), imageX, getHeight() * 3 / 4 + 5, imageWidth, imageWidth, null); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1)); } }
public void paint(Graphics g) { if (myColor == instructorColor) { g.drawString("These favorite colors match", 10, 20); } else { g.drawString("These favorite colors do not match", 10, 20); } }
/** * Draws everything onto the main panel. * * @param page Graphics component to draw on */ public void paintComponent(Graphics page) { super.paintComponent(page); setForeground(Color.cyan); renderer.draw(page, this, offX, offY); // hero.draw(this, page, offX, offY); for (Entity effect : effects) { effect.draw(this, page, offX, offY); /*if (effect instanceof Burst) { Burst pop = (Burst) effect; pop.draw(this, page, offX, offY); }*/ } // Draw hero position information Rectangle r = hero.getBounds(); page.drawString("Position: x = " + (r.x + (r.width >> 1)), SCORE_PLACE_X, SCORE_PLACE_Y); final int tab = 100; final int lineHeight = 20; page.drawString("y = " + (r.y + (r.height >> 1)), SCORE_PLACE_X + tab, SCORE_PLACE_Y); page.drawString("Frame: " + frame, SCORE_PLACE_X, SCORE_PLACE_Y + lineHeight); if (!running) { page.drawString("Game over :(", WIDTH / 2, HEIGHT / 2); } }
public void paint(Graphics g) { g.setColor(Color.gray); g.fillRect(0, 0, w, h); g.setColor(Color.black); g.drawRect(0, 0, w, h); g.setColor(Color.blue); g.fillRect(0, h, w, h); g.setColor(Color.black); g.drawRect(0, h, w, h); g.drawString("resting", 10, 20); g.drawString("waits to swim", 10, h - 20); g.drawString("waits to exit", 10, (3 * h) / 2 - 20); g.drawString("swimming", 10, 2 * h - 20); if (e == null) return; for (int i = 0; i < e.e.length; i++) { switch (e.get(i)) { case 0: rect(g, (i < e.K ? Color.red : Color.green), i, 0); break; case 1: rect(g, (i < e.K ? Color.red : Color.green), i, 1); break; case 2: rect(g, (i < e.K ? Color.red : Color.green), i, 3); break; case 3: rect(g, (i < e.K ? Color.red : Color.green), i, 2); break; default: } } }
public void paintComponent(Graphics g) { int width = (int) Math.round( ((double) curVal / (double) max) * 133.0); // 133: width of the bar image itself g.drawImage(bg, 0, 0, null); g.setColor(Color.WHITE); g.setFont( new Font( Util.Util.getGameFont().getFamily(), Util.Util.getGameFont().getStyle(), Util.Util.getGameFont().getSize() - 4)); if (max < 100) g.drawString(Integer.toString(max), 178, 17); // two pixels needed for the size difference else g.drawString(Integer.toString(max), 174, 17); if (curVal < 100) g.drawString(Integer.toString(curVal), 10, 17); else g.drawString(Integer.toString(curVal), 6, 17); g.setColor(RED); if (width > 133) g.fill3DRect(37, 7, 133, 10, true); // fill to the end if its above max else if (width > 0) // Needed for the 0 effect g.fill3DRect(37, 7, width, 10, true); }
protected void paintComponent(Graphics g) { g.setColor(Color.WHITE); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.BLACK); g.drawOval((int) a1 - 1, (int) a2 - 1, 2, 2); g.drawString("A", (int) a1, (int) a2); g.drawOval((int) b1 - 1, (int) b2 - 1, 2, 2); g.drawString("B", (int) b1, (int) b2); g.drawOval((int) c1 - 1, (int) c2 - 1, 2, 2); g.drawString("C", (int) c1, (int) c2); GraphDrawHelper.drawEdge(g, a1, a2, b1, b2, c1, c2, 8, 45, true); /*double[] m = {0,0}; try { m = GraphToolKit.getCenter(a1, a2, b1, b2, c1, c2); g.drawOval((int)m[0]-1, (int)m[1]-1, 2, 2); g.drawString("M", (int)m[0], (int)m[1]); double r = Math.sqrt((m[0]-a1)*(m[0]-a1)+(m[1]-a2)*(m[1]-a2)); double d = Math.sqrt((c1-a1)*(c1-a1)+(c2-a2)*(c2-a2)); if (r/d>10) throw new GraphException("too linear"); //g.drawOval((int)(m[0]-r), (int)(m[1]-r), (int)(2*r), (int)(2*r)); double[] phi = GraphToolKit.getAngle(a1, a2, b1, b2, c1, c2, m[0], m[1]); g.drawArc((int)(m[0]-r), (int)(m[1]-r), (int)(2*r), (int)(2*r), (int)(phi[0]), (int)(phi[1])); } catch (GraphException e) { System.out.println(e.getMessage()); g.drawLine((int)a1, (int)a2, (int)c1, (int)c2); }*/ }
private void showScale(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.lightGray); int y_step = 20; float[] dash1 = {2f, 0f, 2f}; Stroke strk = g2d.getStroke(); g2d.setStroke( new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash1, 2f)); for (int y = m_y_offset - y_step; y > m_y_offset - (int) (m_height * 0.5); y -= y_step) g2d.drawLine(m_x_offset, y, m_width - m_x_offset, y); for (int y = m_y_offset + y_step; y < m_y_offset + (int) (m_height * 0.5); y += y_step) g2d.drawLine(m_x_offset, y, m_width - m_x_offset, y); for (int x = m_x_offset + y_step; x < m_width - m_x_offset; x += y_step) g2d.drawLine(x, m_y_offset - (int) (m_height * 0.5), x, m_y_offset + (int) (m_height * 0.5)); Font cur_Font = new Font("Arial", Font.BOLD, 8); g.setFont(cur_Font); int i = y_step; for (int y = m_y_offset - y_step; y > m_y_offset - (int) (m_height * 0.5); y -= y_step, i += y_step) g.drawString(i + "", m_width - m_x_offset, y); i = -y_step; for (int y = m_y_offset + y_step; y < m_y_offset + (int) (m_height * 0.5); y += y_step, i -= y_step) g.drawString(i + "", m_width - m_x_offset, y); g2d.setStroke(strk); }
public void render(Graphics g) { Graphics2D g2d = (Graphics2D) g; Font titleFont = new Font("TimesRoman", Font.BOLD, 40); g.setFont(titleFont); g.setColor(Color.WHITE); g.drawString("INSTRUCTIONS", 60, 47); Font textFont = new Font("TimesRoman", Font.BOLD, 20); g.setFont(textFont); g.drawString("Player 1", 20, 95); g.drawString("Player 2", 280, 95); g2d.draw(startGame); g.drawString("Start Game", 277, 188); Font instructionFont = new Font("TimesRoman", Font.BOLD, 14); g.setFont(instructionFont); g.drawString("UP Key: Move Up", 20, 115); g.drawString("DOWN Key: Move Down", 20, 135); g.drawString("W: Move Up", 280, 115); g.drawString("S: Move Down", 280, 135); g.drawString("P: Pause/Resume", 137, 175); g.drawString("R: Restart", 160, 195); }
// färger, se sid 43 i boken // grafiska metoder, sid 248 i boken public void paintComponent(Graphics g) { // för att vara säker på att // "super"-klassen gör sitt // anropar vi den metoden, innan // vi skriver eller ritar super.paintComponent(g); g.drawLine(185, 10, 195, 40); // x1,y1 till x2,y2 g.drawLine(200, 10, 200, 40); g.drawLine(215, 10, 205, 40); g.setColor(Color.white); g.fillOval(50, 30, 300, 150); // x,y,b,h (x,y för ö v h) g.setColor(Color.red); g.drawArc(100, 100, 200, 50, 180, 180); // x,y,b,h,s,l g.setColor(Color.yellow); g.fillRect(200, 100, 30, 30); g.fill3DRect(150, 50, 30, 50, true); // true upphöjd figur g.fill3DRect(250, 50, 30, 50, true); // skriv ut en textsträng, samt ange läget i avståndet från // övre vänstra hörnet i x-led åt höger och i y-led neråt g.drawString("** Tjenare kompis !! **", 20, 20); f = new Font("Arial", Font.BOLD, 30); setBackground(Color.cyan); g.setFont(f); g.setColor(new Color(255, 175, 175)); g.drawString("YEEEEEEEES!!", 100, 250); }
public static void paint(Graphics g) { g.setColor(Color.BLACK); g.fillRect(0, 0, 80, View.getFrameHeight()); int h = (View.getFrameHeight() - 50) / 10; for (int i = 0; i < items.length; i++) { if (selectedItem != -1 && i == selectedItem) { g.setColor(Color.WHITE); if (items[i] != null) { g.drawImage(items[i].getImage(), 5, i * h + (i + 1) * 5, 70, h, null); } g.drawRect(5, i * h + (i + 1) * 5, 70, h); } else { if (items[i] != null) { g.drawImage(items[i].getImage(), 5, i * h + (i + 1) * 5, 70, h, null); } g.setColor(Color.GRAY); g.drawRect(5, i * h + (i + 1) * 5, 70, h); } if (items[i] instanceof HardDrive && ((HardDrive) items[i]).beingProgrammed()) { g.setColor(new Color(1f, 1f, 1f, 0.5f)); g.fillRect(5, i * h + (i + 1) * 5, 70, h); g.setColor(Color.RED); g.setFont(new Font("Arial", Font.BOLD, 11)); g.drawString("Being", 15, i * h + (i + 1) * 5 + 15); g.drawString("Progra", 15, i * h + (i + 1) * 5 + 25); g.drawString("mmed...", 15, i * h + (i + 1) * 5 + 35); } } }
private void drawColorBar(Graphics g) { int minimum, maximum, height; minimum = 100; maximum = 500; height = 1; int finalI = 0; for (int i = 0; i < (maximum - minimum); i++) { float f = 0.75f * i / (float) (maximum - minimum); g.setColor(Color.getHSBColor(0.75f - f, 1.0f, 1.0f)); g.fillRect(getWidth() - 40, height * i + 50, 20, height); finalI = i; } g.setColor(Color.BLACK); g.drawString( String.valueOf(this.opticalReturnPowerController.getMaxValue()), getWidth() - 60, 48); // Max Value g.drawString( String.valueOf(this.opticalReturnPowerController.getMinValue()), getWidth() - 60, finalI + 63); // Min Value }
public void paintComponent(Graphics g) { g.setColor(new Color(96, 96, 96)); image.paintIcon(this, g, 1, 1); FontMetrics fm = g.getFontMetrics(); String[] args = {jEdit.getVersion()}; String version = jEdit.getProperty("about.version", args); g.drawString(version, (getWidth() - fm.stringWidth(version)) / 2, getHeight() - 5); g = g.create((getWidth() - maxWidth) / 2, TOP, maxWidth, getHeight() - TOP - BOTTOM); int height = fm.getHeight(); int firstLine = scrollPosition / height; int firstLineOffset = height - scrollPosition % height; int lines = (getHeight() - TOP - BOTTOM) / height; int y = firstLineOffset; for (int i = 0; i <= lines; i++) { if (i + firstLine >= 0 && i + firstLine < text.size()) { String line = (String) text.get(i + firstLine); g.drawString(line, (maxWidth - fm.stringWidth(line)) / 2, y); } y += fm.getHeight(); } }
protected void drawHistogram(Graphics g, MBinSummary binCnt) { // ******************************** // * Draw the histogram // ******************************** MClusterSummary[] bins; int value; int height; int y; Color color; Font f = g.getFont(); Font newFont = new Font(UIManager.getFont("Label.font").getName(), Font.PLAIN, 14); g.setFont(newFont); bins = binCnt.GetBins(); // _maxBinsIndex // *********************** // draw the outliner even it is zero // *********************** value = bins[0].getCount(); height = (int) ((double) value * _pixel_per_unit); y = _abs_line_height - height; g.setColor(MColorMgr.GetInstance().GetColor(0, MGlobal.FADE_IDX_MAX)); g.fillRect(_bin_cur_x, y, (int) _bin_width, height); g.setColor(Color.BLACK); g.drawString(value + "", (int) _bin_cur_x, y - LABEL_HEIGHT); g.drawString("0", (int) _bin_cur_x, _abs_axis_height); _bin_cur_x += (int) _bin_width_two; // *********************** // * draw the rest // *********************** for (int idx = 1; idx <= binCnt.GetMaxBinIndex(); idx++) { value = bins[idx].getCount(); if (value > 0) { height = (int) ((double) value * _pixel_per_unit); y = _abs_line_height - height; g.setColor(MColorMgr.GetInstance().GetColor(idx, MGlobal.FADE_IDX_MAX)); g.fillRect(_bin_cur_x, y, (int) _bin_width, height); g.setColor(Color.BLACK); g.drawString(value + "", (int) _bin_cur_x, y - LABEL_HEIGHT); g.drawString(idx + "", (int) _bin_cur_x, _abs_axis_height); _bin_cur_x += (int) _bin_width_two; } } g.setFont(f); bins = null; }
public void drawXYAxis(Graphics g) { // x axis: (x0, yn) ~ (xn, yn) // y axis: (x0, y0) ~ (x0, yn) int x0 = Constants.CANVAS_MARGIN_WIDTH; int y0 = Constants.CANVAS_MARGIN_HEIGHT; int xn = x0 + Constants.CANVAS_WIDTH; int yn = y0 + Constants.CANVAS_HEIGHT; g.drawLine(x0, yn, xn, yn); // draw x axis g.drawLine(x0, y0, x0, yn); // draw y axis int tickInt = Constants.CANVAS_HEIGHT / 10; int min = 0; for (int xt = x0 + tickInt; xt < xn; xt += tickInt) { g.drawLine(xt, yn + 5, xt, yn - 5); // int min = (xt - x0) * (xLen / Constants.CANVAS_MARGIN_WIDTH); min += scaleUnit; g.drawString(Integer.toString(min), xt - (min < 10 ? 3 : 7), yn + 20); } // tickInt = Constants.CANVAS_HEIGHT / 10; min = 0; for (int yt = yn - tickInt; yt > Constants.CANVAS_MARGIN_HEIGHT; yt -= tickInt) { g.drawLine(x0 - 5, yt, x0 + 5, yt); // int min = (yt - y0) * (yLen / Constants.CANVAS_MARGIN_HEIGHT); min += scaleUnit; g.drawString(Integer.toString(min), x0 - 32, yt + 5); } }
public void paint(Graphics g) { g.setColor(Color.white); int height = this.getSize().height * 3 / 4; int boxHeight = 10; int boxWidth = 60; int itemWidth = 120; int leftOffset = boxWidth + 10; int margin = 5; g.drawString("Roll-up", leftOffset + margin, height); g.drawString("Air", leftOffset + (1 * itemWidth) + margin, height); g.drawString("Sea", leftOffset + (2 * itemWidth) + margin, height); g.drawString("Ground", leftOffset + (3 * itemWidth) + margin, height); g.drawString("Level-2", leftOffset + (4 * itemWidth) + margin, height); int bottom = height - boxHeight; g.setColor(TPFDDColor.TPFDDPurple); g.fillRect(leftOffset - boxWidth, bottom, boxWidth, boxHeight); g.setColor(TPFDDColor.TPFDDBlue); g.fillRect(leftOffset + (1 * itemWidth) - boxWidth, bottom, boxWidth, boxHeight); g.setColor(TPFDDColor.TPFDDGreen); g.fillRect(leftOffset + (2 * itemWidth) - boxWidth, bottom, boxWidth, boxHeight); g.setColor(TPFDDColor.TPFDDDullerYellow); g.fillRect(leftOffset + (3 * itemWidth) - boxWidth, bottom, boxWidth, boxHeight); g.setColor(Color.black); g.fillRect(leftOffset + (4 * itemWidth) - boxWidth, bottom, boxWidth, boxHeight); }
public void paint(Graphics g) { g.drawRect(0, 0, getSize().width - 1, getSize().height - 1); FontMetrics metrics = getFontMetrics(g.getFont()); int lineHeight = metrics.getHeight() + 2; int line = 1; g.drawString("Start Class loader test...", 1, lineHeight * (line++)); try { SystemProperties.setProperty("microedition.platform", "MicroEmulator-Test"); PreporcessorClassLoader cl = new PreporcessorClassLoader(PreporcessorTest.class.getClassLoader()); cl.disableClassLoad(SystemProperties.class); cl.disableClassLoad(ResourceLoader.class); ResourceLoader.classLoader = cl; cl.addClassURL(PreporcessorTest.TEST_CLASS); g.drawString("ClassLoader created...", 1, lineHeight * (line++)); Class instrumentedClass = cl.loadClass(PreporcessorTest.TEST_CLASS); Runnable instrumentedInstance = (Runnable) instrumentedClass.newInstance(); instrumentedInstance.run(); g.drawString("Looks good!", 1, lineHeight * (line++)); } catch (Throwable e) { g.drawString("Error " + e.toString(), 1, lineHeight * (line++)); e.printStackTrace(); } }
private void drawYTicks(Graphics g) { int hPos = 0; int pPos = 0; for (int i = 0; i < yTicks; i++) { int drawPos = yVal(hPos, maxH) + r; if (hPos % hInc == 0) { // draw line g.setColor(Color.BLACK); g.drawLine(padding - 10, drawPos, padding, drawPos); // draw tick values for herbivores g.setColor(Color.BLUE); g.drawString("" + hPos, padding - 50, drawPos + r); // draw tick values for predators g.setColor(Color.RED); g.drawString("" + pPos, padding - 50, drawPos + r + 20); } hPos += hInc; pPos += pInc; } }
@Override public void paint(Graphics g) { if (state == GameState.Running) { g.drawImage(background, bg1.getBgX(), bg1.getBgY(), this); g.drawImage(background, bg2.getBgX(), bg2.getBgY(), this); paintTiles(g); ArrayList<Projectile> projectiles = robot.getProjectiles(); for (int i = 0; i < projectiles.size(); i++) { Projectile p = (Projectile) projectiles.get(i); g.setColor(Color.YELLOW); g.fillRect(p.getX(), p.getY(), 10, 5); } // g.drawRect((int)robot.rect.getX(), (int)robot.rect.getY(), // (int)robot.rect.getWidth(), (int)robot.rect.getHeight()); // g.drawRect((int)robot.rect2.getX(), (int)robot.rect2.getY(), // (int)robot.rect2.getWidth(), (int)robot.rect2.getHeight()); g.drawImage(currentSprite, robot.getCenterX() - 61, robot.getCenterY() - 63, this); g.drawImage(hanim.getImage(), hb.getCenterX() - 48, hb.getCenterY() - 48, this); g.drawImage(hanim.getImage(), hb2.getCenterX() - 48, hb2.getCenterY() - 48, this); g.setFont(font); g.setColor(Color.WHITE); g.drawString(Integer.toString(score), 740, 30); } else if (state == GameState.Dead) { g.setColor(Color.BLACK); g.fillRect(0, 0, 800, 480); g.setColor(Color.WHITE); g.drawString("Dead", 360, 240); } }