Java -практика использования

        

Способы заливки



Листинг 9.5. Способы заливки

import java.awt.*;

import Java.awt.geom.*;

import java.awt.image.*;

import j ava.awt.event.*;


class PaintTest extends Frame{ PaintTest(String s){ super(s) ;

setSize(300, 300);
 

setVisible(true);
 

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent ev){

System.exit(0);
}

});
 

}

public void paint(Graphics gr){ 

Graphics2D g = (Graphics2D)gr; 

Bufferedlmage bi =

new Bufferedlmage(20, 20, Bufferedlmage.TYPE_IMT_RGB);
 

Graphics2D big = bi.createGraphics();
 

big.draw(new Line2D.Double(0.0, 0.0, 10.0, 10.0));
 

big.draw(new Line2D.Double(0.0, 10.0, 10.0, 0.0));
 

TexturePaint tp = new TexturePaint(bi,

  new Rectangle2D.Double(0.0, 0.0, 10.0, 10.0));
 

g.setPaint(tp);

g.fil(new Rectangle2D. Double (50, 50, 200, 200));
 

GradientPaint gp =

new GradientPaint(100, 100, Color.white,

150, 150, Color.black, true);
g.setPaint(gp);

g.filKnew Ellipse2D.Double (100, 100, 200, 200));
 

public static void main(String[] args){

new PaintTest(" Способы заливки");
 

}



Содержание раздела