Quote:
Originally Posted by tjakowenko
Perhaps someone provide a brief outline to illustrate a simple example of creating a class in file “A” and using it in file “B”?
|
Quick, rudimentary example here. Two classes in same project and package. Main instantiates a new instance of the ManualDrive class, then invokes method driveMe() on it. This program will actually work btw
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.SimpleRobot;
public class Main extends SimpleRobot {
ManualDrive drive = new ManualDrive();
public void autonomous() {
}
public void operatorControl() {
while (this.isOperatorControl()) {
drive.driveMe();
}
}
}
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
public class ManualDrive {
Jaguar jag1 = new Jaguar(1);
Jaguar jag2 = new Jaguar(2);
RobotDrive drive = new RobotDrive(jag1, jag2);
Joystick controllerOne = new Joystick(1);
// constructor, needed to instantiate, can be empty
public ManualDrive() {
}
public void driveMe() {
drive.arcadeDrive(controllerOne);
}
}