Go to Post Experience...you can't buy it, you might be able to get some for free by reading CD a lot, but usually you have to earn it, and it's not always fun. - MrForbes [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:26.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi