Public feed #726385

Mine

public java v1 · immutable
Raw Edit
·published 2007-10-05 04:00 UTC
rendered paste body
import javax.swing.*;import java.awt.*;import java.awt.geom.*;/**  * JPanel for the Turtle GUI display. * Displays the Turtle in a GUI. */public class TurtleDisplayPanel extends JPanel {	/** Turtle object to display in the GUI */	private Turtle[] turtles;	/** Turtle icon */	private ImageIcon turtleIcon = new ImageIcon("turtle.png");		/**	 * Constructs the <code>TurtleDisplayPanel</code>.	 * @param turtle The Turtle to display in the JPanel.	 */	public TurtleDisplayPanel(Turtle[] turtles){		this.turtles = turtles;		setBackground(Color.white);		setPreferredSize(new Dimension(200,200));	}	public void setTurtles(Turtle[] turtles){		this.turtles = turtles;	}	/**	 * Paints the JPanel. 	 * @param g The graphics object to use for painting.	 */	public void paintComponent(Graphics g){		super.paintComponent(g);		for(Turtle turtle : turtles){			if(turtle != null){				//Graphics2D transformableGraphics = (Graphics2D)g;				//transformableGraphics.setTransform(AffineTransform.getRotateInstance(-turtle.getDirection()+Math.PI/2,this.getWidth()/2+turtle.getX(),this.getHeight()/2-turtle.getY()));				g.fillOval(getWidth()/2+turtle.getX(),getHeight()/2-turtle.getY(),10,10);				System.out.println(turtle.getX());				//g.drawImage(turtleIcon.getImage(),this.getWidth()/2+turtle.getX()-7,this.getHeight()/2-turtle.getY()-9,null);				//transformableGraphics.drawImage(turtleIcon.getImage(),this.getWidth()/2+turtle.getX()-7,this.getHeight()/2-turtle.getY()-9,null);				//transformableGraphics.setTransform(AffineTransform.getRotateInstance(-turtle.getDirection()+Math.PI/2,this.getWidth()/2+turtle.getX(),this.getHeight()/2-turtle.getY()));				//g.drawImage(turtle.getTurtleIcon().getImage(),this.getWidth()/2+turtle.getX()-7,this.getHeight()/2-turtle.getY()-9,null);				//transformableGraphics.drawImage(turtle.getTurtleIcon().getImage(),this.getWidth()/2+turtle.getX()-7,this.getHeight()/2-turtle.getY()-9,null);			}		}	}}