TextureChooserpublic class TextureChooser extends JPanel Four types of Paint displayed: Geometry, Text & Image Textures and
a Gradient Paint. Paints can be selected with the Mouse. |
Fields Summary |
---|
public static Object | texture | public int | num |
Constructors Summary |
---|
public TextureChooser(int num)
this.num = num;
setLayout(new GridLayout(0,2,5,5));
setBorder(new TitledBorder(new EtchedBorder(), "Texture Chooser"));
add(new Surface(getGeomTexture(), this, 0));
add(new Surface(getImageTexture(), this, 1));
add(new Surface(getTextTexture(), this, 2));
add(new Surface(getGradientPaint(), this, 3));
|
Methods Summary |
---|
public static java.awt.TexturePaint | getGeomTexture()
BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
Graphics2D tG2 = bi.createGraphics();
tG2.setBackground(Color.white);
tG2.clearRect(0,0,5,5);
tG2.setColor(new Color(211,211,211,200));
tG2.fill(new Ellipse2D.Float(0,0,5,5));
Rectangle r = new Rectangle(0,0,5,5);
return new TexturePaint(bi,r);
| public java.awt.GradientPaint | getGradientPaint()
return new GradientPaint(0,0,Color.white,80,0,Color.green);
| public java.awt.TexturePaint | getImageTexture()
Image img = DemoImages.getImage("HotJava-16.gif", this);
int iw = img.getWidth(this);
int ih = img.getHeight(this);
BufferedImage bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
Graphics2D tG2 = bi.createGraphics();
tG2.drawImage(img, 0, 0, this);
Rectangle r = new Rectangle(0,0,iw,ih);
return new TexturePaint(bi,r);
| public java.awt.TexturePaint | getTextTexture()
Font f = new Font("Times New Roman", Font.BOLD, 10);
TextLayout tl = new TextLayout("Java2D", f, new FontRenderContext(null, false, false));
int sw = (int) tl.getBounds().getWidth();
int sh = (int) (tl.getAscent()+tl.getDescent());
BufferedImage bi = new BufferedImage(sw, sh, BufferedImage.TYPE_INT_RGB);
Graphics2D tG2 = bi.createGraphics();
tG2.setBackground(Color.white);
tG2.clearRect(0,0,sw,sh);
tG2.setColor(Color.lightGray);
tl.draw(tG2, 0, (float) tl.getAscent());
Rectangle r = new Rectangle(0,0,sw,sh);
return new TexturePaint(bi,r);
| public static void | main(java.lang.String[] s)
Frame f = new Frame("Java2D Demo - TextureChooser");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
f.add("Center", new TextureChooser(0));
f.pack();
f.setSize(new Dimension(400,400));
f.setVisible(true);
|
|