// @topic T11754 2D Graphics demo 04 -- controller and subject added // @brief class <tt>SubjectShopper</tt> -- sample simulation subject package shopsimulation; import java.awt.Graphics2D; import java.awt.geom.Line2D; public class SubjectShopper implements ISubject { /* L 59 56 59 132 L 34 80 88 80 L 59 132 32 173 L 59 131 82 171 */ boolean flagVisible = false; Line2D.Double line1 = new Line2D.Double( 59, 56, 59, 132 ); Line2D.Double line2 = new Line2D.Double( 34, 80, 88, 80 ); Line2D.Double line3 = new Line2D.Double( 59, 132, 32, 173 ); Line2D.Double line4 = new Line2D.Double( 59, 131, 82, 171 ); public SubjectShopper( int posX, int posY ) { move( posX, posY ); } public SubjectShopper( int posX, int posY, boolean flagVisible ) { this( posX, posY ); setVisible( flagVisible ); } @Override public void draw( Graphics2D gr2d ) { if ( !flagVisible ) { return; } gr2d.draw( line1 ); gr2d.draw( line2 ); gr2d.draw( line3 ); gr2d.draw( line4 ); } @Override public void move( int incrementX, int incrementY ) { line1.setLine( line1.getX1() + incrementX, line1.getY1() + incrementY, line1.getX2() + incrementX, line1.getY2() + incrementY ); line2.setLine( line2.getX1() + incrementX, line2.getY1() + incrementY, line2.getX2() + incrementX, line2.getY2() + incrementY ); line3.setLine( line3.getX1() + incrementX, line3.getY1() + incrementY, line3.getX2() + incrementX, line3.getY2() + incrementY ); line4.setLine( line4.getX1() + incrementX, line4.getY1() + incrementY, line4.getX2() + incrementX, line4.getY2() + incrementY ); } @Override public void setVisible( boolean flagVisible ) { this.flagVisible = flagVisible; } }