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”.

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.

.

You can do that quite easily in fact.

package WriteMessage.*;

public class WriteMessage{
public void writeUM(int line, String Message) {
//lots of code
}
}

In your main robot code file:

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.

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.

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

Thanks though.

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.