Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: object switching with event listener

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Location
    Germany
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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?

    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];
     
    			wiimote.addWiiMoteEventListeners(control1);
    			wiimote.addWiiMoteEventListeners(control2);
     
    			wiimote.activateMotionSensing();
    			wiimote.activateContinuous();
    			wiimote.getStatus();
    		}
    	}
     
    	@Override
    	public void onSwitchEvent() {
    		// TODO Auto-generated method stub
     
    	}
    }

    and the other class

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


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: object switching with event listener

    Crossposted: object switching with event listener

  3. The Following User Says Thank You to PhHein For This Useful Post:

    jps (June 27th, 2013)

Similar Threads

  1. Event Listener for ComboBox
    By JamesdTurnham in forum What's Wrong With My Code?
    Replies: 8
    Last Post: December 9th, 2012, 09:31 PM
  2. Switching between classes
    By SACoder in forum Object Oriented Programming
    Replies: 4
    Last Post: July 20th, 2012, 03:17 PM
  3. Switching between frames from a seperate class
    By kurt-hardy in forum AWT / Java Swing
    Replies: 4
    Last Post: February 14th, 2011, 04:19 AM
  4. swing - switching JPanels
    By bbr201 in forum Java Theory & Questions
    Replies: 2
    Last Post: August 5th, 2010, 09:18 AM
  5. Is it worth switching from PHP to JSP
    By mydarkpassenger in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: April 3rd, 2010, 02:23 AM

Tags for this Thread