import com.stevesoft.phreida.*; import java.awt.*; import java.io.*; import java.net.*; /** This test shows you how you can take an application that already works using awt, and give it the ability to generate PDF. To implement this, Test5.java was modified slightly. */ public class Test6 extends Component { public static void main(String[] args) throws Exception { Test6 test = new Test6(); Frame f = new Frame("Test 6"); f.setLayout(new GridLayout(1,1)); f.add(test); f.pack(); f.setSize(300,460); f.show(); // This is the part, the next three lines, // that we would add to allow our application // to generate PDF. PGraphics pg = new PGraphics("test6.pdf",0,0,300,460); test.paint(pg); pg.dispose(); } public void paint(Graphics g) { Toolkit tk = Toolkit.getDefaultToolkit(); g.setClip(makeStar(125,125,60,75)); URL url = Test5.class.getResource("onintro.gif"); Image im = tk.getImage(url); g.drawImage(im,65,95,this); int del = 4; int radius = 50; int x = 100, y = 100; for(int i=0;i <= 460;i+=20) { radius += 2*del; y -= del; x -= del; g.setColor(Color.green); g.drawArc(x,y,radius,radius,i,300); g.setColor(Color.blue); g.drawArc(x,y,radius,radius,i+300,60); } } public static Polygon makeStar(int xc,int yc,int r1,int r2) { int[] xpoints = new int[10]; int[] ypoints = new int[10]; for(int i=0;i<10;i++) { double a = Math.PI/5*i+Math.PI/10; double r = r1+r2*(i%2); xpoints[i] = xc+(int)(r*Math.cos(a)+.5); ypoints[i] = yc+(int)(r*Math.sin(a)+.5); } return new Polygon(xpoints,ypoints,10); } }