Public feed #726382

Untitled

public java v1 · immutable
Raw Edit
·published 2007-10-05 03:59 UTC
rendered paste body
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();	}}