R
Ross
I would like to write a base class from which child classes inherit a
public static void main( String args[] ) method.
As readers can probably guess, but problem is that the main method
doesn't know which class to create to start the program running.
The parent class is called Game. I can't write a method:
public static void main( String args[] )
{
Game g = new Game();
g.setVisible( true );
}
as it runs the base class.
At present I have a method (simplified, from memory) which takes the
name of the class as a runtime argument. E.g.
public static void main( String args[] ) throws Exception
{
Class c = Class.forName( args[0] );
Game g = (Game) c.newInstance();
g.setVisible( true );
}
This works, but requires the name of the class to be given as an
argument. If I could find out the name of the class that had been
executed, then I could solve this problem. But I've looked in the
System class properties, I've looked in Runtime, and I haven't found
anything.
Is there a solution to this problem? I would like the solution to be
cross-platform.
public static void main( String args[] ) method.
As readers can probably guess, but problem is that the main method
doesn't know which class to create to start the program running.
The parent class is called Game. I can't write a method:
public static void main( String args[] )
{
Game g = new Game();
g.setVisible( true );
}
as it runs the base class.
At present I have a method (simplified, from memory) which takes the
name of the class as a runtime argument. E.g.
public static void main( String args[] ) throws Exception
{
Class c = Class.forName( args[0] );
Game g = (Game) c.newInstance();
g.setVisible( true );
}
This works, but requires the name of the class to be given as an
argument. If I could find out the name of the class that had been
executed, then I could solve this problem. But I've looked in the
System class properties, I've looked in Runtime, and I haven't found
anything.
Is there a solution to this problem? I would like the solution to be
cross-platform.