List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
From source file:Main.java
public void render(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.WHITE); Font font = new Font("Verdana", Font.PLAIN, 20); g2d.setFont(font);/*from w ww .ja va 2s.c om*/ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); FontMetrics fm = g2d.getFontMetrics(); String option = "This is a test"; int x = (getWidth() - fm.stringWidth(option)) / 2; int y = ((getHeight() - fm.getHeight()) / 2); g2d.drawString(option, x, y + fm.getAscent()); g2d.drawRect((int) x - 20, (int) y - 10, (int) fm.stringWidth(option) + 40, (int) fm.getHeight() + 20); }
From source file:Textures.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(212, 212, 212)); g2d.drawRect(10, 15, 90, 60);//from w w w .j a v a2 s . co m BufferedImage bimage1 = null; URL url1 = ClassLoader.getSystemResource("a.png"); try { bimage1 = ImageIO.read(url1); } catch (IOException ioe) { ioe.printStackTrace(); } Rectangle rect1 = new Rectangle(0, 0, bimage1.getWidth(), bimage1.getHeight()); TexturePaint texture1 = new TexturePaint(bimage1, rect1); g2d.setPaint(texture1); g2d.fillRect(10, 15, 90, 60); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED); g2d.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2); g2d.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight()); render(g);//from w w w . java 2s .c o m g2d.dispose(); }
From source file:TimerBasedAnimation.java
public void render(int w, int h, Graphics2D g2) { g2.setColor(Color.BLUE); g2.draw(ellipse); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED); g2d.fill(poly);/*from www .ja va2 s . co m*/ g2d.setColor(Color.GREEN); g2d.translate(50, 100); g2d.fill(triangleShape); g2d.dispose(); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(getBackground()); g2d.fillRect(0, 0, getWidth(), getHeight()); if (image != null) { int x = getWidth() - image.getWidth(); int y = getHeight() - image.getHeight(); g2d.drawImage(image, x, y, this); }/*from www. ja va2 s.c o m*/ super.paintComponent(g2d); g2d.dispose(); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED); g2d.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight()); g2d.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2); Font font = new Font("Arial", Font.BOLD, 48); g2d.setFont(font);/*from w w w .j av a 2 s .co m*/ FontMetrics fm = g2d.getFontMetrics(); int x = ((getWidth() - fm.stringWidth(text)) / 2); int y = ((getHeight() - fm.getHeight()) / 2) + fm.getAscent(); g2d.setColor(Color.BLACK); g2d.drawString(text, x, y); g2d.dispose(); }
From source file:TextQualityDemoVALUE_TEXT_ANTIALIAS_LCD_HBGR.java
public void paintComponent(Graphics g) { Dimension d = this.getSize(); BufferedImage backBuffer = (BufferedImage) this.createImage(d.width, d.height); Graphics2D g2 = backBuffer.createGraphics(); g2.setColor(Color.WHITE); g2.fillRect(0, 0, d.width, d.height); g2.setColor(Color.BLACK);/*ww w. jav a 2 s .co m*/ g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, hintValue); g2.drawRect(0, 0, d.width - 1, d.height - 1); g2.drawString("abcdefghijklmnopqrstuvwxyz", 20, 40); g2.drawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 20, 60); g2.drawString("1234567890-=!@#$%^&*()_+,./<>?", 20, 80); g.drawImage(backBuffer, 0, 0, this); }
From source file:Colors.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(12, 16, 116)); g2d.fillRect(10, 15, 90, 60);//from ww w . ja v a2 s. c o m g2d.setColor(new Color(42, 19, 31)); g2d.fillRect(130, 15, 90, 60); g2d.setColor(new Color(70, 7, 23)); g2d.fillRect(250, 15, 90, 60); g2d.setColor(new Color(10, 10, 84)); g2d.fillRect(10, 105, 90, 60); g2d.setColor(new Color(22, 21, 61)); g2d.fillRect(130, 105, 90, 60); g2d.setColor(new Color(21, 98, 69)); g2d.fillRect(250, 105, 90, 60); g2d.setColor(new Color(217, 146, 54)); g2d.fillRect(10, 195, 90, 60); g2d.setColor(new Color(63, 121, 186)); g2d.fillRect(130, 195, 90, 60); g2d.setColor(new Color(131, 121, 11)); g2d.fillRect(250, 195, 90, 60); }
From source file:MainClass.java
public void paint(Graphics g) { if (layouts == null) getLayouts(g);//from w w w .j a v a2s. c o m Point pen = new Point(0, 0); Graphics2D g2d = (Graphics2D) g; g2d.setColor(java.awt.Color.black); // or a property g2d.setFont(font); Iterator it = layouts.iterator(); while (it.hasNext()) { TextLayout layout = (TextLayout) it.next(); pen.y += (layout.getAscent()); g2d.setFont(font); layout.draw(g2d, pen.x, pen.y); pen.y += layout.getDescent(); } }