TurtlePanelExample - turtle.forward(10); } if

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; i public class TurtlePanelExample extends JPanel{ private World world; private Turtle turtle; public TurtlePanelExample(){ world = new World(500,500); world.hide(); turtle = new Turtle(world); this.add(world); } public TurtlePanelExample(int width, int height){ world = new World(width,height); world.hide(); turtle = new Turtle(world); this.add(world); } public void drawCommands(){ for(int i = 1; i <= 20; i++){ turtle.forward(10 * i); turtle.turn(90); pause(1000); } } public void drawCommand(String command){ if (command.equals("up")){ turtle.setHeading(0); turtle.forward(10); } if (command.equals("down")){ turtle.setHeading(180);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: turtle.forward(10); } if (command.equals(&quot;left&quot;)){ turtle.setHeading(270); turtle.forward(10); } if (command.equals(&quot;right&quot;)){ turtle.setHeading(90); turtle.forward(10); } } public static void pause(int interval){ try{ Thread.sleep(interval); } catch(java.lang.InterruptedException e){System.out.println(&quot;An Exception occurred!&quot;);} } public static void main(Stringargs){ TurtlePanelExample panel = new TurtlePanelExample(500,500); JFrame frame = new JFrame (&quot;My Turtle Panel&quot;); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.getContentPane().add (panel); frame.pack(); frame.setVisible(true); panel.drawCommands(); } }...
View Full Document

This note was uploaded on 01/30/2010 for the course CS 1316 taught by Professor Staff during the Spring '08 term at Georgia Institute of Technology.

Page1 / 2

TurtlePanelExample - turtle.forward(10); } if

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online