Log in

View Full Version : Adding additional classes, in different files in Newbeans


tjakowenko
29-01-2011, 19:54
Greetings,

Does anyone know how to add additional classes/files to a project created from an FRC iterative template? I add a new .java file to my project that includes a new public class, methods, etc. I can see the new file in Netbeans file navigator, but when I try to declare the new class in my main .java file, it doesn’t find it as the system is only looking the WPI library. How can I get the project to recognize additional classes and methods from different files?

Thanks in advance,

~TJ

sjspry
29-01-2011, 20:12
If you go to "New File" (Ctrl+N), it should add it in your project so it is seeable. Did you add it in a different package (different set of folders)? If so, hit Alt+Enter on the line where it gives you the error and it should say "Add import from ..."

That's the only problem I can see, if that's not it, perhaps a bit more description?

tjakowenko
29-01-2011, 20:23
Interesting....

Using alt-Enter I can add the file/class to the WPILib, but that is the only option. I'd prefer to add the files & classes to my project/src folder rather than modify the WPI library. Any thoughts?

Patrick Chiang
29-01-2011, 20:51
0. Open up the Projects Panel in Netbeans

1. Find the package where your "main" class is. This would be called the IterativeRobot or something you named it.

2. Right click on that package.

3. New>Class.

tjakowenko
29-01-2011, 23:32
Thanks for the insight.

We've found a bug in the Robot Drive WPI library class and we're trying to hack a fix until an update is released from WPI. I'm bringing the class local to make the change, but I'm having issues referencing the local version of the class.

When adding the class locally the only option that comes up is the default package and I'm having issues with using some of the method declarations within the class.

I'm continuing to play the option and really appreciate your insight.

I would like to temporarily make the change to the library, but it's read-only and I can't seem to change the attribute. Any chances you know how to modify the WPI library attributes?


Thanks again,

~TJ

tjakowenko
30-01-2011, 10:43
Still can't seem to find a way to instantiate a class from a file other that the main. All attempts fail. Perhaps someone provide a brief outline to illustrate a simple example of creating a class in file “A” and using it in file “B”?

Much appreciated.......

~TJ

davidthefat
30-01-2011, 10:46
Ok, go click on the "projects" tab and while it is open, take a screenshot of the screen and I will help you.

wdell
30-01-2011, 11:12
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 :)

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();
}
}
}

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);
}
}

tjakowenko
03-02-2011, 12:45
Thanks you for your help. We have been able to change the WPI lib.