View Single Post
  #6   Spotlight this post!  
Unread 16-02-2011, 11:27
dbeckwith's Avatar
dbeckwith dbeckwith is offline
Lead Programmer
AKA: Daniel Beckwith
FRC #3205 (The Patriots)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: USA
Posts: 84
dbeckwith is an unknown quantity at this point
Re: Joystick(int,int,int) has protected access

The reason why that constructor is protected is that you're not supposed to use it if you are just making a Joystick object (which assumes you are using an Attack 3 joystick, so it sets up the axes and buttons according to that joystick). But if you are trying to make a Joystick object that is not for an Attack 3, then Jared's suggestion would be the right thing to do. Make your own subclass of Joystick to represent your gamepad. In that case you be representing your own custom Joystick, so you would need to customize the axes and buttons.
Some more complete example code might be:
Code:
import edu.wpi.first.wpilibj.Joystick;

public class Gamepad extends Joystick {
  
  final static int NUM_AXES = 3; // these would be the default values for the
  final static int NUM_BUTTONS = 11; // Attack 3 joysticks included in the KOP
  
  Gamepad(int USBport) {
    super(USBport, NUM_AXES, NUM_BUTTONS); // initialize Joystick with the provided USB port
                                           // and the constants for number of buttons and axes
  }
  
}
Extending the Joystick class basically makes it so Gamepad inherits all the methods and variables that Joystick has (and allows you to access protected methods and variables), but you can add in more functionality.
__________________
q = (2*b) | ~(2*b);

if (life.getLemons() != null) this.lemonade = new Drink(life.getLemons());
else throw new NoLemonsException("What now?");


Reply With Quote