// The copyright of this program is reserved by NL. /* Turtle Graphics / V_lȐ */ /* */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Ex061015c extends JApplet implements ActionListener{ double th,Leng; double minl; dTurtle t; boolean flag=false; JComboBox cb2; String cbl2[]={"=15","=30","=45","=60","=75","=90","=105","=120"}; double ang[]={15.0,30.0,45.0,60.0,75.0,90.0,105.0,120.0}; public void init(){ Container cp = getContentPane(); JPanel pl = new JPanel(); pl.setLayout(null); pl.setBackground(Color.black); cb2 = new JComboBox(cbl2); cb2.setBounds(0,0,80,20); cb2.setSelectedIndex(0); cb2.addActionListener(this); pl.add(cb2); t = new dTurtle(200,380); t.setColor(Color.green); cp.add(pl); } public void actionPerformed(ActionEvent event){ th = ang[cb2.getSelectedIndex()]; Leng=90.0; minl=1.0; flag=true; repaint(); } public void paint(Graphics g){ super.paint(g); if(flag==true) tree(Leng,g); } public void tree(double length,Graphics g){ t.move(length,g); if(length>minl){ t.turn(th); tree(length*.375,g); t.turn(-th*2); tree(length*.375,g); t.turn(th); t.turn(-3.5); tree(length*.75,g); t.turn(3.5); } t.warp(-length); } }