Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about main class and static code example included

Status
Not open for further replies.

Chrissirhc

Programmer
May 20, 2000
926
GB
When I made a program I had a really small main class.
Look at it below: (I've changed the names so that you can see what they are)

private class MyMainClassWhichIsRunToRunTheProgram
{
private static MainFrame myMainProgramWindow;

public static void main(String args[])

{
myMainProgramWindow = new MainFrame("The title");
}
}

Is this the normal way to start a program. I have to make myMainProgramWindow static so that I can reference it within main???.

What other way could I do it?

Cheers

Chris
 
I always do it like this (though I would like to know as well
if it's the correct way to deal with it)

public MyMainClassWhichIsToRunTheProgram {

private MainFrame myMainFrame;

public MyMainClassWhichIsToRunTheProgram() {

myMainFrame = new MainFrame();
myMainFrame.someMethod();
}

public static void main (String args[]) {

new MyMainClassWhichIsToRunTheProgram();

}

}

you can also declare the instancevariable myMainFrame
as

public MainFrame myMainFrame = new MainFrame();


This is quite the same.


I hope it helps (and I hope I'm right in this one)

Swamphen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top