Определение перьев
Листинг 9.4. Определение перьев
import j ava.awt.*;
import j ava.awt.geom. *;
import j ava.awt.event.*;
class StrokeTest extends Frame{
StrokeTest(String s) {
super (s) ;
setSize(500, 400);
setvisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent ev)(
System.exit(0);
}
});
}
public void paint(Graphics gr){
Graphics2D g = (Graphics2D)gr;
g.setFont(new Font("Serif", Font.PLAIN, 15));
BasicStroke penl = new BasicStroke(20, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER,30);
BasicStroke pen2 = new BasicStroke(20, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND);
BasicStroke репЗ = new BasicStroke(20, BasicStroke.CAP_SQUARE,
BasicStroke.JOIN_BEVEL);
floatf] dashl = {5, 20};
BasicStroke pen4 = new BasicStroke(10, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_BEVEL, 10, dashl, 0);
float[] dash2 = (10, 5, 5, 5};
BasicStroke pen5 = new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, dash2, 0);
g.setStroke(penl);
g.draw(new Rectangle2D.Double(50, 50, 50, 50));
g.draw(new Line2D.Double(50, 180, 150, 180));
g.setStroke(pen2);
g.draw(new Rectangle2D.Double(200, 50, 50, 50));
g.draw(new Line2D.Double(50, 230, 150, 230));
g.setStroke(реnЗ);
g.draw(new Rectangle2D.Double(350, 50, 50, 50));
g.draw(new Line2D.Double(50, 280, 150, 280));
g.drawstring("JOIN_MITER", 40, 130);
g.drawstring("JOIN_ROUND", 180, 130);
g.drawstring("JOINJBEVEL", 330, 130);
g.drawstring("CAP_BUTT", 170, 190);
g.drawstring("CAP_ROUND", 170, 240);
g.drawstring("CAP_SQUARE", 170, 290);
g.setStroke(pen5);
g.drawfnew Line2D.Double(50, 330, 250, 330));
g.setStroke(pen4);
g.draw(new Line2D.Double(50, 360, 250, 360));
g.drawString("{10, 5, 5, 5,...}", 260, 335);
g.drawstring(
"(5,
10,...}", 260, 365);
}
public static void main(String[] args){
new StrokeTest("Моя программа");
}
}