In this example we will see how to interface events in a sprite wrapper.
Type a key to switch between hours mode and date mode.
Click with the mouse to switch between 12-hours and 24-hours clock display.
Things are not really different between this case and the previous one. The MouseWrapper implements MouseListener to intercept mouse events.
Here is the code which modifies the state of the TimeWrapper:
The main difference is the way to associate the MouseListener with the playfield. We can incorporate it directly in the wrapper: when a new parent playfield is set for the sprite, we can associate the MouseListener with that new parent playfield (no more worry about that! ):
And now, in the MouseTimeApplet applet, we only to instantiate objects:
...// Creates the time labelSpriteLabellabel=newSpriteLabel("");label.setFont(newFont("SansSerif",Font.BOLD,24));label.setColor(Color.gray);timeSprite=newTimeWrapper(label);Spritesprite=newMovingWrapper(newMouseWrapper(timeSprite),2,2);playfield.addSprite(sprite);...