Hi, I’ve tried everything I could think of to try to load a file inside an enum, but can’t get a way to reference to the current sketchPath statically. Does anyone know any posible solution?
That’s a small part of the code, but hopefully it’d be enough for you to understand the problem.
import java.io.File;
public enum SoundEffect {
BELL("bell.wav"),
BLOWER("blower.wav");
// Each sound effect has its own clip, loaded with its own sound file.
private Clip clip;
// Constructor to construct each element of the enum with its own sound file.
SoundEffect(String soundFileName) {
try {
// Use URL (instead of File) to read from disk and JAR.
File soundFile = new File(soundFileName);
tbh I don’t know why sketchPath() isn’t a static method, but in the meantime I’m using the constructor method, but it’s a huge overhead as I had to make a container class for the enum, as I couldn’t get it to work with the enum itself :S
If you use multiple windows, you will have multiple applet instances. They have their own path assigned internally. Notice this path location can be “overriden” meaning you can ensure all instantiated applets points to the same sketch by providing extra arguments during their construction. This should be done if they want to get the access the same pool of user resources aka. images, fonts, etc. Why is this design like this? No clue. However, it is not that bad. At least, you can change the default path definition, if needed.
I still wonder, under what circumpstances would you have multiple window applets assigned to different sketches but running under the same instance of java :S
It’s a matter of flexibility. They could easily declare field sketchPath as static.
In such case, the last created [p]PApplet[/u] would determine the sketchPath for all PApplet instances.