import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; /** JFrame containing the LOGO interpreter. * Contains the TurtleDisplayPanel, and a JTextField for entering commands. Implements ActionListener to interpret the commands. */ public class LogoFrame extends JFrame implements ActionListener{ /** Turtle to display in the TurtleDisplayPanel */ //private Turtle[] turtles; /** TurtleDisplayPanel to display in the JFrame */ private TurtleDisplayPanel panel; /** JTextField in the JFrame */ private JTextField f; /** Parser object */ private Parser parse; /** * Constructs a new LogoFrame. * Adds the TurtleDisplayPanel and JTextField and sets the frame to visible. */ public LogoFrame(){ this.setTitle("LOGO"); parse = new Parser(); panel = new TurtleDisplayPanel(parse.getTurtles()); f = new JTextField(); f.addActionListener(this); panel.setLayout(new BorderLayout()); add(panel,BorderLayout.CENTER); add(f,BorderLayout.SOUTH); } /** * ActionEvent handler that interprets commands. * Uses Scanner to parse the commands. Invalid commands do nothing and throw no exceptions */ public void actionPerformed(ActionEvent event){ parse.parseLine(f.getText()); panel.setTurtles(parse.getTurtles()); f.setText(""); panel.repaint(); } }