List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:MainClass.java
public int print(Graphics g, PageFormat pf, int pageIndex) { if (pageIndex != 0) return NO_SUCH_PAGE; Graphics2D g2 = (Graphics2D) g; g2.setFont(new Font("Serif", Font.PLAIN, 36)); g2.setPaint(Color.black); g2.drawString("www.java2s.com", 100, 100); Rectangle2D outline = new Rectangle2D.Double(pf.getImageableX(), pf.getImageableY(), pf.getImageableWidth(), pf.getImageableHeight());//from w ww . j a v a 2s. c o m g2.draw(outline); return PAGE_EXISTS; }
From source file:MainClass.java
private BufferedImage createImage() { BufferedImage bim;// www .ja v a 2 s . com 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); } return bim; }
From source file:Main.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow); g2d.setPaint(gp1); g2d.fillRect(20, 20, 300, 40);//from www .j a va 2 s.c o m }
From source file:Textures.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; TexturePaint slatetp = new TexturePaint(s, new Rectangle(0, 0, 90, 60)); g2d.setPaint(slatetp); g2d.fillRect(10, 15, 90, 60);/* w w w .j a va2 s . c o m*/ }
From source file:misc.GradientTranslucentWindowDemo.java
public GradientTranslucentWindowDemo() { super("GradientTranslucentWindow"); setBackground(new Color(0, 0, 0, 0)); setSize(new Dimension(300, 200)); setLocationRelativeTo(null);/*from w w w . j av a 2 s . c om*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { @Override protected void paintComponent(Graphics g) { if (g instanceof Graphics2D) { final int R = 240; final int G = 240; final int B = 240; Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0), 0.0f, getHeight(), new Color(R, G, B, 255), true); Graphics2D g2d = (Graphics2D) g; g2d.setPaint(p); g2d.fillRect(0, 0, getWidth(), getHeight()); } } }; setContentPane(panel); setLayout(new GridBagLayout()); add(new JButton("I am a Button")); }
From source file:net.sf.webphotos.tools.Thumbnail.java
private static Image estampar(Image im) { try {//w w w .j a va 2 s . co m Image temp = new ImageIcon(im).getImage(); BufferedImage buf = new BufferedImage(temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) buf.getGraphics(); g2.drawImage(temp, 0, 0, null); g2.setBackground(Color.BLUE); Dimension dimensaoFoto = new Dimension(im.getWidth(null), im.getHeight(null)); // aplicar texto if (texto != null) { Util.out.println("aplicando texto " + texto); Font fonte = new Font(txFamilia, txEstilo, txTamanho); g2.setFont(fonte); FontMetrics fm = g2.getFontMetrics(fonte); Dimension dimensaoTexto = new Dimension(fm.stringWidth(texto), fm.getHeight()); Point posTexto = calculaPosicao(dimensaoFoto, dimensaoTexto, txMargem, txPosicao); g2.setPaint(txCorFundo); g2.drawString(texto, (int) posTexto.getX() + 1, (int) posTexto.getY() + 1 + fm.getHeight()); g2.setPaint(txCorFrente); g2.drawString(texto, (int) posTexto.getX(), (int) posTexto.getY() + fm.getHeight()); } // aplicar marca dagua if (marcadagua != null) { Image marca = new ImageIcon(marcadagua).getImage(); int rule = AlphaComposite.SRC_OVER; float alpha = (float) mdTransparencia / 100; Point pos = calculaPosicao(dimensaoFoto, new Dimension(marca.getWidth(null), marca.getHeight(null)), mdMargem, mdPosicao); g2.setComposite(AlphaComposite.getInstance(rule, alpha)); g2.drawImage(marca, (int) pos.getX(), (int) pos.getY(), null); } g2.dispose(); //return (Image) buf; return Toolkit.getDefaultToolkit().createImage(buf.getSource()); } catch (Exception e) { Util.err.println("[Thumbnail.estampar]/ERRO: Inesperado - " + e.getMessage()); e.printStackTrace(Util.err); return im; } }
From source file:MainClass.java
public void paint(Graphics g) { BufferedImage bim;// w w w. j a va 2s .c om 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:GradientsLine.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; GradientPaint gp1 = new GradientPaint(5, 25, Color.green, 2, 2, Color.black, true); g2d.setPaint(gp1); g2d.fillRect(20, 140, 300, 40);//from ww w . ja v a 2 s . c om }
From source file:Main.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true); g2d.setPaint(gp1); g2d.fillRect(20, 20, 300, 40);/*from www.j av a2 s .c o m*/ }
From source file:GradientsMiddle.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; GradientPaint gp1 = new GradientPaint(0, 0, Color.orange, 0, 20, Color.black, true); g2d.setPaint(gp1); g2d.fillRect(20, 260, 300, 40);//ww w. jav a 2 s . c o m }