/Users/lyon/j4p/src/bookExamples/ch26Graphics/sprials/SpiralComponent.java

1    package bookExamples.ch26Graphics.sprials; 
2     
3     
4    public abstract class SpiralComponent 
5            extends javax.swing.JComponent { 
6        public bookExamples.ch26Graphics.sprials.Spirals s = 
7                new bookExamples.ch26Graphics.sprials.Spirals(); 
8     
9        public SpiralComponent(java.awt.Dimension d) { 
10           s.setSize(d); 
11           setPreferredSize(d); 
12       } 
13    
14       public abstract void paint(java.awt.Graphics g); 
15    
16       public void setSize(java.awt.Dimension d) { 
17           s.setSize(d); 
18       } 
19    
20       static SpiralComponent getComponent(java.awt.Dimension d) { 
21           return 
22                   new SpiralComponent(d) { 
23                       public void paint(java.awt.Graphics g) { 
24    
25                           s.setSize(getSize()); 
26                           // s.fermatsSpiral(4, Math.PI, g); 
27                           // s.archimedesImage(param,g); 
28                           // s.equiangularSpiral(g); 
29                           s.drawTree(g); 
30                           param = param + .1; 
31                           // repaint(100); 
32    
33                       } 
34                   }; 
35       } 
36    
37       static double param = 0.1; 
38    
39       public static void main(String args[]) { 
40           java.awt.Dimension d = new java.awt.Dimension(400, 400); 
41           gui.ClosableJFrame cf = 
42                   new gui.ClosableJFrame(); 
43           java.awt.Container c = cf.getContentPane(); 
44           c.setLayout(new java.awt.FlowLayout()); 
45           c.add(getComponent(d)); 
46           cf.setSize(d); 
47           cf.setVisible(true); 
48       } 
49   }