Reputation: 454
How can I run some code after calling MainFrame with Java Applets? Is this possible?
Frame frame = new MainFrame(new ClassName(),256,256);
System.out.println("This won't print!");
Can someone explain how I can get that to print after calling MainFrame?
Upvotes: 0
Views: 418
Reputation: 83587
As a simple example, take a look at this code:
package mainframe;
import javax.swing.JFrame;
/**
*
* @author codeguru <[email protected]>
*/
public class MainFrame extends JFrame {
public static void main(String[] args) {
JFrame frame = new MainFrame();
System.out.println("This prints.");
}
}
This gives the expected output:
This prints.
From your original code, I don't see where the applet is that you refer to in your question's title. In order to help you, we need to know more about MainClass
and ClassName
. These look like custom classes which you wrote or are part of the example you are studying.
Upvotes: 1
Reputation: 8255
Java does not have a MainFrame
class in it's standard libraries.
What you are probably seeing is a program that can run as both an Applet and an application.
When running as an application, the main GUI class is apparently called MainFrame
, and the line you quote is where it is constructed. Note that it receives an instance of class ClassName
; that's probably where the logic of the program resides (the model).
Your System.out.println
will be called after the MainFrame(...)
constructor is done.
Only if the system is exited (by a call to System.exit(int)
for example) before it can return from the constructor call, will your System.out.println
not be reached.
Upvotes: 1