Go to Post I know it's hard to believe, but there actually IS life after FIRST. - jleibs [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 24-09-2010, 20:49
nealpatel nealpatel is offline
Registered User
FRC #1777
 
Join Date: Jan 2010
Location: Lenexa, KS
Posts: 8
nealpatel is an unknown quantity at this point
Access Classes from different file

Does anyone know how to access java classes from a different file? We have always used only one file for all code but now it's so big so I was wondering if there is any way (I'm sure there is some way but idk) to do that.

Like for "User Messages", we made a class "writeUM".

Quote:
public void writeUM(int line, String Message) {

if(line == 1) {
uM.println(DriverStationLCD.Line.kMain6, 1, Message);
uM.updateLCD();
}
else if(line == 2) {
uM.println(DriverStationLCD.Line.kUser2, 1, Message);
uM.updateLCD();
}
else if(line == 3) {
uM.println(DriverStationLCD.Line.kUser3, 1, Message);
uM.updateLCD();
}
else if(line == 4) {
uM.println(DriverStationLCD.Line.kUser4, 1, Message);
uM.updateLCD();
}
else if(line == 5) {
uM.println(DriverStationLCD.Line.kUser5, 1, Message);
uM.updateLCD();
}
else if(line == 6) {
uM.println(DriverStationLCD.Line.kUser6, 1, Message);
uM.updateLCD();
}
}
So this is at the end of our program. I was wondering if I can put this in a different file and call that file instead.

Thanks.

.
__________________
-------------------------------------------------
Neal Patel
Team 1777
Shawnee Mission West
Viking Robotics

e-mail: neal.patel11@yahoo.com
Reply With Quote
  #2   Spotlight this post!  
Unread 25-09-2010, 15:17
buildmaster5000 buildmaster5000 is offline
Trying to program the swerve drive
AKA: Alex
FRC #2421 (Rolling Thunder Robotics)
Team Role: Alumni
 
Join Date: May 2009
Rookie Year: 2009
Location: Northern Virginia
Posts: 207
buildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud of
Re: Access Classes from different file

You can do that quite easily in fact.

package WriteMessage.*;

Code:
public class WriteMessage{
public void writeUM(int line, String Message) {
//lots of code
}
}
In your main robot code file:

Code:
import edu.wpi.first.wpilibj.*;
import WriteMessage.*;

public class RobotFile{
///when you want to access you method
WriteMessage.writeUM(5,"Hello World");
}
NetBeans does a really good job of helping you out on this type of stuff.
__________________
-Alex



2010 Washington DC Regional: Engineering Excellence Award
Reply With Quote
  #3   Spotlight this post!  
Unread 27-09-2010, 22:19
lusterlink's Avatar
lusterlink lusterlink is offline
Registered User
FRC #1160 (FireBird Robotics)
Team Role: Programmer
 
Join Date: Aug 2010
Rookie Year: 2009
Location: USA
Posts: 9
lusterlink is an unknown quantity at this point
Re: Access Classes from different file

Neal-

Quick question. Do you mean accessing the class or method outside the file? Because it seems your asking if you can access the method outside the file.

If you want to access the class, simply add the import to the top of the file.

If you want to access the method, you might have to look towards static methods.

P.S. I might be completely wrong, if so correct me.
buildmaster, I attempted to run your code... Its a no go, I think because method must be static.
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 27-09-2010, 22:26
nealpatel nealpatel is offline
Registered User
FRC #1777
 
Join Date: Jan 2010
Location: Lenexa, KS
Posts: 8
nealpatel is an unknown quantity at this point
Re: Access Classes from different file

I actually figured out what I wanted to do. It's basically what you wrote but I made it easier and different.

Thanks though.
__________________
-------------------------------------------------
Neal Patel
Team 1777
Shawnee Mission West
Viking Robotics

e-mail: neal.patel11@yahoo.com
Reply With Quote
  #5   Spotlight this post!  
Unread 27-09-2010, 22:30
nealpatel nealpatel is offline
Registered User
FRC #1777
 
Join Date: Jan 2010
Location: Lenexa, KS
Posts: 8
nealpatel is an unknown quantity at this point
Re: Access Classes from different file

Quote:
Originally Posted by lusterlink View Post
Neal-

Its a no go, I think because method must be static.
IDK what you mean and what I meant by class or method.

Anyways, I figured out what I wanted.

And if you failed to run my code, you did something completely wrong as this code is working since forever, I just want the whole "writeUM" thing in a different file.

I'm good now. Thanks everyone who tried to help.
__________________
-------------------------------------------------
Neal Patel
Team 1777
Shawnee Mission West
Viking Robotics

e-mail: neal.patel11@yahoo.com
Reply With Quote
Reply


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Different approach from a rookie player feliks_rosenber Rules/Strategy 12 15-01-2007 15:59
What information can we access from the camera? Total Meltdown Programming 37 01-02-2006 11:24
What information can we access from the camera? Total Meltdown Programming 13 08-01-2006 13:50
Combining multiple objects in different files into the same scene and file? DinkyDogg 3D Animation and Competition 8 19-02-2005 19:14
Good book to learn MS Access from? Elgin Clock Math and Science 2 05-10-2004 20:20


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

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