/* File: FractalCanvas.java Author: Stefan Robila Description: This is a simple exension of the Canvas class with additions done to facilitate the drawing of the fractal and the printing of the information related to the fractal Structure of FractalCanvas with the description of the members public class FractalCanvas extends Canvas { private String line1,line2,line3; - lines of text that will contain information related to the fractal private int depth; - the depth of the fractal that will be drawn private LFractal f; - the fractal to be drawn private boolean has_fractal=false;- if false, paint() will not do anything, if true, paint() will draw the fractal together with the related information Methods: ------- public void paint(Graphics g); - draws the fractal public void draw(LFractal what,int how_much); - used to set the type of fractal and the depth } */ // The code: import java.awt.*; public class FractalCanvas extends Canvas { private String line1,line2,line3; private int depth = 0; private LFractal f; private boolean has_fractal=false; // paint() will draw the fractal and the related information when the // has_fractal is true public void paint(Graphics g) { if (has_fractal) { // compose the lines to be printed. the functions called are // nothing else but methods from the LFractal class that return // values of the data members. See LFractal.java for a detailed // description line1 = "Fractal "+f.getName()+" refined "+depth+" times"; line2 = "Start: "+f.getInitial()+ " Angle: "+f.getAngle(); line3 = "Rule: "+f.getStart()+"->"+f.getReplace(); // print the lines on the screen g.drawString(line1,20,20); g.drawString(line2,20,35); g.drawString(line3,20,50); // refine and print the fractal f.expand(depth); f.DrawPattern(g); // used to reset the standard data for the fractal f.clear(); }; } // draw() will just set the fractal and the depth of the refination and // then it will call repaint() public void draw(LFractal what,int how_much) { f = what; depth = how_much; // of course, since you have a fractal, now you can draw it has_fractal=true; repaint(); } }