Tue Nov 11, 2008 8:32 pm
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
public class ShowTexturePaint extends JPanel {
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
BufferedImage bufferedImage = new BufferedImage(8, 8,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bufferedImage.createGraphics();
g2.setColor(Color.red);
g2.fillRect(0, 0, 8, 8);
g2.setColor(Color.gray);
g2.fillOval(0, 0, 8, 8);
Rectangle2D rect = new Rectangle2D.Double(5, 5, 8, 8);
g2d.setPaint(new TexturePaint(bufferedImage, rect));
Ellipse2D oval = new Ellipse2D.Double(8,8,250,250);
g2d.fill(oval);
}
public static void main(String args[]) {
JFrame frame = new JFrame("Show Texture Paint");
ShowTexturePaint texturePaint = new ShowTexturePaint();
frame.getContentPane().add("Center", texturePaint);
frame.setSize(350, 300);
frame.setVisible(true);
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.