1 9 10 15 package org.nfunk.jepexamples; 16 17 import java.applet.*; 18 import java.awt.*; 19 import java.awt.event.*; 20 21 public class Fractal extends Applet implements ActionListener { 22 23 private TextField exprField, itField; 24 private Button button, button2; 25 private FractalCanvas complexCanvas; 26 27 28 29 public void init () { 30 initComponents(); 31 } 32 33 34 private void initComponents () { 35 GridBagLayout gridbag = new GridBagLayout(); 36 GridBagConstraints c = new GridBagConstraints(); 37 38 setLayout(gridbag); 39 c.fill = GridBagConstraints.BOTH; 40 41 String expr = getParameter("initialExpression"); 43 if (expr!=null) 44 exprField = new TextField(expr); 45 else 46 exprField = new TextField(""); 47 48 49 exprField.setBackground (java.awt.Color.white); 50 exprField.setName ("exprField"); 51 exprField.setFont (new Font ("Dialog", 0, 11)); 52 exprField.setForeground (Color.black); 53 exprField.addTextListener (new java.awt.event.TextListener () { 54 public void textValueChanged (java.awt.event.TextEvent evt) { 55 exprFieldTextValueChanged (evt); 56 } 57 } 58 ); 59 60 c.gridx = 0; 61 c.gridy = 0; 62 c.weightx = 1; 63 gridbag.setConstraints(exprField, c); 64 add(exprField); 65 66 c.gridx = 1; 68 c.gridy = 0; 69 c.weightx = 0.2; 70 button = new Button("Render"); 71 gridbag.setConstraints(button, c); 72 add(button); 73 button.addActionListener(this); 74 75 itField = new TextField("20"); 77 itField.addTextListener (new java.awt.event.TextListener () { 78 public void textValueChanged (java.awt.event.TextEvent evt) { 79 itFieldTextValueChanged(evt); 80 } 81 } 82 ); 83 84 c.gridx = 0; 85 c.gridy = 1; 86 c.weightx = 1; 87 gridbag.setConstraints(itField, c); 88 add(itField); 89 90 91 c.gridx = 0; 93 c.gridy = 2; 94 c.gridwidth = 2; 95 c.weighty = 1; 96 98 complexCanvas = new FractalCanvas(expr, exprField); 99 gridbag.setConstraints(complexCanvas, c); 100 add(complexCanvas); 101 } 102 103 104 105 private void exprFieldTextValueChanged (java.awt.event.TextEvent evt) { 106 String newExpressionString = exprField.getText(); 107 complexCanvas.setExpressionString(newExpressionString); 108 } 110 111 private void itFieldTextValueChanged (java.awt.event.TextEvent evt) { 112 Integer newIterationsValue = new Integer (itField.getText()); 113 complexCanvas.setIterations(newIterationsValue.intValue()); 114 } 116 117 public void actionPerformed(ActionEvent ae) { 118 String str = ae.getActionCommand(); 119 if (str.equals("Render")) { 120 String newExpressionString = exprField.getText(); 121 complexCanvas.setExpressionString(newExpressionString); 122 complexCanvas.repaint(); 123 } 124 } 125 } 126 | Popular Tags |