Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Adding additional classes, in different files in Newbeans (http://www.chiefdelphi.com/forums/showthread.php?t=90476)

tjakowenko 29-01-2011 19:54

Adding additional classes, in different files in Newbeans
 
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

Re: Adding additional classes, in different files in Newbeans
 
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

Re: Adding additional classes, in different files in Newbeans
 
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

Re: Adding additional classes, in different files in Newbeans
 
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

Re: Adding additional classes, in different files in Newbeans
 
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

Re: Adding additional classes, in different files in Newbeans
 
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

Re: Adding additional classes, in different files in Newbeans
 
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

Re: Adding additional classes, in different files in Newbeans
 
Quote:

Originally Posted by tjakowenko (Post 1011617)
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);
    }
}


tjakowenko 03-02-2011 12:45

Re: Adding additional classes, in different files in Newbeans
 
Thanks you for your help. We have been able to change the WPI lib.


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

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