Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. Graphics2D g2d = bi.createGraphics();
  2. g2d.setColor(Color.RED);
  3. g2d.fillRect(0,0,100,100);
  4.  
  5. BufferedImage bi;
  6. Graphics2D g2d = bi.createGraphics();
  7. g2d.setPaint (new Color(r, g, b));
  8. g2d.fillRect (0, 0, bi.getWidth(), bi.getHeight());
  9.  
  10. TexturePaint tp = new TexturePaint(myImage, new Rectangle(0, 0, 16, 16));
  11.  
  12. g2d.setPaint(tp);
  13.  
  14. public class TexturePanel extends JPanel {
  15.  
  16. private TexturePaint paint;
  17.  
  18. public TexturePanel(BufferedImage bi) {
  19. super();
  20. this.paint = new TexturePaint(bi, new Rectangle(0, 0, bi.getWidth(), bi.getHeight()));
  21. }
  22.  
  23. @Override
  24. protected void paintComponent(Graphics g) {
  25. Graphics2D g2 = (Graphics2D) g;
  26. g2.setPaint(paint);
  27. g2.fill(new Rectangle(0, 0, getWidth(), getHeight()));
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement