Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By PhHein

Thread: object switching with event listener

  1. #1
    clavius11 is offline Member
    Join Date
    Jun 2013
    Rep Power

    Default object switching with event listener

    I need your help. I'm making a controlling program that use Wiimote, and I need to make 2 different type of control. each controller code is defined in the class controlType1 and controlType2 (which the #2 isn't included here, but mostly it is the same with #1).

    the Idea is, when I press certain button on the WiiMote, the controller switched from type1 to type2. I've instantiate 2 objects, and it should removes the listener of one of the object when the button is pressed and change it to the other object.

    currently, I've gone this far and get stuck here. any Idea how should I do this?

    Java Code:
    public class WiiDroneControl implements ControlSwitchListener {
    	private Wiimote wiimote;
    	private WiimoteListener control1 = (WiimoteListener) new controlType1(this);
    	private WiimoteListener control2 = (WiimoteListener) new controlType2(this);
    	public WiiDroneControl() {
    		Wiimote wiimotes[] = WiiUseApiManager.getWiimotes(1, true);
    		if(wiimotes!= null && wiimotes.length > 0)
    			wiimote = wiimotes[0];
    	public void onSwitchEvent() {
    		// TODO Auto-generated method stub
    and the other class

    Java Code:
    public class controlType1 implements WiimoteListener{
    	ControlSwitchListener listener = null;
    	public controlType1(ControlSwitchListener l) {
    		listener = l;
    	public void onButtonsEvent(WiimoteButtonsEvent e) {
    		// TODO Auto-generated method stub
    		if (e.isButtonOnePressed())
    			//switch object when this button is pressed

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Rep Power

    Default Re: object switching with event listener

    DarrylBurke likes this.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Rep Power

    Default Re: object switching with event listener

    Hmm. Personally, I'd put a onButtonsEvent(WiimoteButtonsEvent e) into WiiDroneControl and make that one the only listener while also making a third WiimoteListener object called "activeController". In that method, I'd first check if e.isButtonOnePressed() and switch activeController to the one that isn't active, and if any other button is pressed, pass on the WiimoteButtonsEvent to the active controller.

Similar Threads

  1. Cant dispatch event or listener?
    By heatblazer in forum Advanced Java
    Replies: 5
    Last Post: 05-25-2013, 09:58 PM
  2. applet event listener
    By jobud9 in forum New To Java
    Replies: 4
    Last Post: 01-29-2012, 07:15 AM
  3. Implementing an event listener?
    By jammas615 in forum Java 2D
    Replies: 3
    Last Post: 07-04-2011, 04:15 PM
  4. how to add event Listener to Image
    By shane5317 in forum Java 2D
    Replies: 3
    Last Post: 03-13-2011, 12:36 PM
  5. Listener for SWT event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-08-2008, 10:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts