Timer.getTime without extending SimpleBulletApplication or multiple SimpleBulletApplication

I have a method I’m building in a class that requires the timer.getTime() method. I can’t use it unless that class extends SimplaeBulletApplication. I extend it, and Netbeans doesn’t find any problems however, my program crashed when I try to use it.



I’m calling this method form my actual game, which is also extending SimpleBulletApplication. When it crashes, it points to the line in my new class that uses timer.getTime() or timer.getResolution().



why do you think this is causeing such a problem and how can I use these methods without having to extending SImpleBulletApplication?

Where are you using the timer? It only gets set after you call start() on the Application.

Maybe you can provide a stack trace of the crash?

I’ll provide a stack trace when I get home but overall, I’m Instantiating the secondary class within my game class globally. Then I am calling the method in question in the main event loop of the game class.



I attempted to instantiate a simpleBulletApplication within my secondary class, then calling myBulletApp.timer.getTime(); however that gives me an error in which I have to implement the abstract classes for the SimpleBulletApplication timer method.



I’ve also tried calling myGame.timer.getTime(); however this is a protected method and cannot be accessed.

This is basically what I tried at first and how I expected it to work (which doesn’t).



[java]

public class myGame extends SimpelBulletApplication{



secondaryClass secondClass = new secondaryClass();



//… standard setup code and main method here…



public void simpleUpdate(){

secondClass();

}//end simpleUpdate

}//end class[/java]



I tried the below code first with problems:

[java]

public class SecondaryClass{



public void methodInQuestion(){

System.out.println( timer.getTime() ); //<-- error points here

}//end method in question

}//end class

[/java]





Extending SimpleBulleteApplication crashes when reading the getTime(); call:



[java]

public class SecondaryClass extends SimpleBulletApplication{



public void methodInQuestion(){

System.out.println( timer.getTime() ); //<-- error points here

}//end method in question

}//end class

[/java]



If I attempt to instantiate a SimpleBulletApplication I get a bunch of empty abstract methods to override:





[java]

public class SecondaryClass{

SimpleBulletApplication BulletApp = new SimpleBulletApplication (){

//Tons of empty methods to fill

}

public void methodInQuestion(){

System.out.println(timer.getTime());

}//end method in question

}//end class

[/java]



When i try to call the myGame, I get an error saying that getTime(); is protected:



[java]

public class SecondaryClass{



public void methodInQuestion(){

System.out.println( myGame.timer.getTime() ); //<-- error points here

}//end method in question

}//end class

[/java]

Just store the tpf once in the loop, otherwise its corrupted anyway.

I can store the variables in the myGame, but then how would I call them from my secondaryMethod without explicitly passing them to the secondary? I’m not a great java programmer so I don’t know of how to do something like “myGame.getTimerValue” from within the secondaryClass. If you know of a way, please illuminate me.



The problem with this is that I need a starting and ending measurement, and I may use any number of other methods that would require start and stop times. If each one of them has a different starting and ending time, then I end up having a lot of complicated code in the main event loop. I need it also to by dynamic, so that I may end up having any number of secondaryClass-type methods and I’ll never know how many so I can’t hard code this into the main event loop. I really just need to be able to access the timer functions directly from my secondaryClass.