List of usage examples for java.awt Graphics2D drawString
public abstract void drawString(AttributedCharacterIterator iterator, float x, float y);
From source file:DrawSimpleText.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = new Font("Serif", Font.PLAIN, 96); g2.setFont(font);/*from w ww . j a v a 2s. c o m*/ g2.drawString("Java Source and Support", 40, 120); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = new Font("Serif", Font.PLAIN, 96); g2.setFont(font);// ww w .j ava 2 s. c om g2.drawString("Please \u062e\u0644\u0639 slowly.", 40, 80); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = new Font("Serif", Font.PLAIN, 96); g2.setFont(font);/*from w ww . ja v a 2s.co m*/ g2.drawString("jade", 40, 120); }
From source file:weka.core.ChartUtils.java
/** * Render a combined histogram and pie chart from summary data * //from ww w. j av a 2 s.c om * @param width the width of the resulting image * @param height the height of the resulting image * @param values the values for the chart * @param freqs the corresponding frequencies * @param additionalArgs optional arguments to the renderer (may be null) * @return a buffered image * @throws Exception if a problem occurs */ public static BufferedImage renderCombinedPieAndHistogramFromSummaryData(int width, int height, List<String> values, List<Double> freqs, List<String> additionalArgs) throws Exception { String plotTitle = "Combined Chart"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; List<String> opts = new ArrayList<String>(); opts.add("-title=distribution"); BufferedImage pie = renderPieChartFromSummaryData(width / 2, height, values, freqs, false, true, opts); opts.clear(); opts.add("-title=histogram"); BufferedImage hist = renderHistogramFromSummaryData(width / 2, height, values, freqs, opts); BufferedImage img = new BufferedImage(width, height + 20, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); g2d.setFont(new Font("SansSerif", Font.BOLD, 12)); g2d.setColor(Color.lightGray); g2d.fillRect(0, 0, width, height + 20); g2d.setColor(Color.black); FontMetrics fm = g2d.getFontMetrics(); int fh = fm.getHeight(); int sw = fm.stringWidth(plotTitle); g2d.drawImage(pie, 0, 20, null); g2d.drawImage(hist, width / 2 + 1, 20, null); g2d.drawString(plotTitle, width / 2 - sw / 2, fh + 2); g2d.dispose(); return img; }
From source file:FontHints.java
protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.WHITE);//from w w w. jav a 2 s . co m g2d.fillRect(0, 0, getWidth(), getHeight()); g2d.setColor(Color.BLACK); g2d.drawString("Unhinted string", 10, 20); if (desktopHints != null) { g2d.addRenderingHints(desktopHints); } g2d.drawString("Desktop-hinted string", 10, 40); }
From source file:com.alibaba.webx.tutorial.app1.module.screen.simple.SayHiImage.java
private void writeImage(OutputStream out) throws IOException { BufferedImage img = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = img.createGraphics(); g2d.setPaint(Color.red);/*ww w . j a v a 2 s . co m*/ g2d.setFont(new Font("Serif", Font.BOLD, 36)); g2d.drawString("Hi there, how are you doing today?", 5, g2d.getFontMetrics().getHeight()); g2d.dispose(); ImageIO.write(img, "jpg", out); }
From source file:MainClass.java
public void paint(Graphics g) { BufferedImage bim;/*from w ww .j a v a2s . c o m*/ TexturePaint tp; String mesg = "www.java2s.com"; Font myFont = new Font("Lucida Regular", Font.BOLD, 72); Color[] colors = { Color.red, Color.blue, Color.yellow, }; int width = 8, height = 8; bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bim.createGraphics(); for (int i = 0; i < width; i++) { g2.setPaint(colors[(i / 2) % colors.length]); g2.drawLine(0, i, i, 0); g2.drawLine(width - i, height, width, height - i); } Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight()); tp = new TexturePaint(bim, r); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setPaint(tp); g2d.setFont(myFont); g2d.drawString(mesg, 20, 100); }
From source file:$.SayHiImage.java
private void writeImage(OutputStream out) throws IOException { BufferedImage img = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = img.createGraphics(); g2d.setPaint(Color.red);/* w w w .j ava2s.c o m*/ g2d.setFont(new Font("Serif", Font.BOLD, 36)); g2d.drawString("Hi there, how are you doing today?", 5, g2d.getFontMetrics().getHeight()); g2d.dispose(); ImageIO.write(img, "jpg", out); }
From source file:Main.java
public void paint(Graphics g) { BufferedImage bim;//from ww w . ja v a 2s . c o m TexturePaint tp; String mesg = "www.java2s.com"; Font myFont = new Font("Lucida Regular", Font.BOLD, 72); Color[] colors = { Color.red, Color.blue, Color.yellow, }; int width = 8, height = 8; bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bim.createGraphics(); for (int i = 0; i < width; i++) { g2.setPaint(colors[(i / 2) % colors.length]); g2.drawLine(0, i, i, 0); g2.drawLine(width - i, height, width, height - i); } Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight()); tp = new TexturePaint(bim, r); System.out.println(tp.getAnchorRect()); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setPaint(tp); g2d.setFont(myFont); g2d.drawString(mesg, 20, 100); }
From source file:Main.java
public void paint(Graphics g) { BufferedImage bim;//from w ww .ja v a2 s.com TexturePaint tp; String mesg = "www.java2s.com"; Font myFont = new Font("Lucida Regular", Font.BOLD, 72); Color[] colors = { Color.red, Color.blue, Color.yellow, }; int width = 8, height = 8; bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bim.createGraphics(); for (int i = 0; i < width; i++) { g2.setPaint(colors[(i / 2) % colors.length]); g2.drawLine(0, i, i, 0); g2.drawLine(width - i, height, width, height - i); } Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight()); tp = new TexturePaint(bim, r); System.out.println(tp.getImage()); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setPaint(tp); g2d.setFont(myFont); g2d.drawString(mesg, 20, 100); }