View Single Post
  #8   Spotlight this post!  
Unread 30-01-2011, 11:12
wdell wdell is offline
Registered User
AKA: William Dell
FRC #3999 (Shadetree Mechanics)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Killeen, Texas
Posts: 55
wdell has a spectacular aura aboutwdell has a spectacular aura about
Re: Adding additional classes, in different files in Newbeans

Quote:
Originally Posted by tjakowenko View Post
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);
    }
}
Reply With Quote