// // Flower.java // BodiesInASetting // // Created by Guy Lapalme on 20/05/05. // Copyright (c) 2005 Universite de Montreal. All rights reserved. // Modified in June 2014 // import java.awt.Image; import javax.swing.JPopupMenu; class Flower extends AnimatedBody{ Flower(){ super(""); } // CLASS part Flower(String name, MyPoint pos){ super(name); setPosition(pos); } // class variables and instances private static int nbAspects = 1; private static int nbDirections = 2; private static Image[][] film; private static JPopupMenu flowerMenu; private static String[] flowerMenuLabels = {"open","close"}; public static void initialize(){ setting.registerAnimatedBody(Flower.class); film = initFilm("Flower",nbAspects,nbDirections); flowerMenu = appendMenu(appendMenu(new JPopupMenu(),aniBodyMenuLabels), flowerMenuLabels); } // INSTANCE part public boolean isOpen(){ return getDirection() == 0; } public void open(){ setDirection(0); } public void close(){ setDirection(1); } // definition of abstract methods of AnimatedBody public int getNbAspects(){ return nbAspects; } public int getNbDirections(){ return nbDirections; } public Image[][] film(){ return film; } public void showMenu(int xMouse,int yMouse){ thisBody=this; flowerMenu.show(setting,xMouse,yMouse); } public void perform(String action){ if(action.equals("open")){ open(); trace("open"); } else if (action.equals("close")){ close(); trace("close"); } else super.perform(action); setting.repaint(); } // MAIN for stand alone testing public static void main(String[] args){ Flower rose = new Flower("rose",new MyPoint(100,100)); System.out.println(rose); rose.close(); System.out.println("After rose.close:"+rose); System.out.println("rose.isOpen:"+rose.isOpen()); rose.moveTo(new MyPoint(200,200)); System.out.println("After rose.moveTo(200@200):"+rose); } // method main }