< prev index next >

src/demo/share/jfc/J2Ddemo/java2d/demos/Fonts/Tree.java

Print this page




  34 
  35 import static java.awt.Color.BLUE;
  36 import static java.awt.Color.GREEN;
  37 import static java.awt.Color.RED;
  38 import static java.awt.Color.WHITE;
  39 import java.awt.Color;
  40 import java.awt.Font;
  41 import java.awt.Graphics2D;
  42 import java.awt.font.TextLayout;
  43 import java.awt.geom.AffineTransform;
  44 import java2d.AnimatingSurface;
  45 
  46 
  47 /**
  48  * Transformation of characters.
  49  */
  50 @SuppressWarnings("serial")
  51 public class Tree extends AnimatingSurface {
  52 
  53     private char theC = 'A';
  54     private Character theT = new Character(theC);
  55     private Character theR = new Character((char) (theC + 1));
  56 
  57     public Tree() {
  58         setBackground(WHITE);
  59     }
  60 
  61     @Override
  62     public void reset(int w, int h) {
  63     }
  64 
  65     @Override
  66     public void step(int w, int h) {
  67         setSleepAmount(4000);
  68         theT = new Character(theC = ((char) (theC + 1)));
  69         theR = new Character((char) (theC + 1));
  70         if (theR.compareTo(new Character('z')) == 0) {
  71             theC = 'A';
  72         }
  73     }
  74 
  75     @Override
  76     public void render(int w, int h, Graphics2D g2) {
  77         int mindim = Math.min(w, h);
  78         AffineTransform at = new AffineTransform();
  79         at.translate((w - mindim) / 2.0,
  80                 (h - mindim) / 2.0);
  81         at.scale(mindim, mindim);
  82         at.translate(0.5, 0.5);
  83         at.scale(0.3, 0.3);
  84         at.translate(-(Twidth + Rwidth), FontHeight / 4.0);
  85         g2.transform(at);
  86         tree(g2, mindim * 0.3, 0);
  87 
  88     }
  89     static Font theFont = new Font(Font.SERIF, Font.PLAIN, 1);
  90     static double Twidth = 0.6;




  34 
  35 import static java.awt.Color.BLUE;
  36 import static java.awt.Color.GREEN;
  37 import static java.awt.Color.RED;
  38 import static java.awt.Color.WHITE;
  39 import java.awt.Color;
  40 import java.awt.Font;
  41 import java.awt.Graphics2D;
  42 import java.awt.font.TextLayout;
  43 import java.awt.geom.AffineTransform;
  44 import java2d.AnimatingSurface;
  45 
  46 
  47 /**
  48  * Transformation of characters.
  49  */
  50 @SuppressWarnings("serial")
  51 public class Tree extends AnimatingSurface {
  52 
  53     private char theC = 'A';
  54     private Character theT = Character.valueOf(theC);
  55     private Character theR = Character.valueOf((char) (theC + 1));
  56 
  57     public Tree() {
  58         setBackground(WHITE);
  59     }
  60 
  61     @Override
  62     public void reset(int w, int h) {
  63     }
  64 
  65     @Override
  66     public void step(int w, int h) {
  67         setSleepAmount(4000);
  68         theT = Character.valueOf(theC = ((char) (theC + 1)));
  69         theR = Character.valueOf((char) (theC + 1));
  70         if (theR.compareTo(Character.valueOf('z')) == 0) {
  71             theC = 'A';
  72         }
  73     }
  74 
  75     @Override
  76     public void render(int w, int h, Graphics2D g2) {
  77         int mindim = Math.min(w, h);
  78         AffineTransform at = new AffineTransform();
  79         at.translate((w - mindim) / 2.0,
  80                 (h - mindim) / 2.0);
  81         at.scale(mindim, mindim);
  82         at.translate(0.5, 0.5);
  83         at.scale(0.3, 0.3);
  84         at.translate(-(Twidth + Rwidth), FontHeight / 4.0);
  85         g2.transform(at);
  86         tree(g2, mindim * 0.3, 0);
  87 
  88     }
  89     static Font theFont = new Font(Font.SERIF, Font.PLAIN, 1);
  90     static double Twidth = 0.6;


< prev index next >