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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application & Applet in same program

Status
Not open for further replies.

puredesi5

Programmer
Sep 26, 2001
50
0
0
US
Does anyone know of AN example (same program) on the web which can be run as an application and as applet?
 
I don't know of an example offhand, but this code snippet should help...

Code:
public class MyApplet extends JApplet
{
    public void init()
    {
        ...
    }
    
    public static void main( String[] args )
    {
        // construct and initialize applet
        final MyApplet applet = new MyApplet();
        applet.init();
        
        // create frame to contain applet
        JFrame containerFrame = new JFrame( "MyApplet Frame" );
        containerFrame.getContentPane().add( applet );
        containerFrame.pack();
        containerFrame.show();
    }
    
} // end class MyApplet
The above code illustrates how to create an applet subclass that can be run as an applet (via appletviewer or an HTML page) or from the mainline.

Hope this helps,
Adam
 
Adam: Thank you! Thank you! You are genius. I really appreciate your help.

Puredesi5
 
I tried and it works. Does anyone know how I can get same title "MyApplet Frame" regardless of how program is executed (application or applet)?

Currently, I get title only if I run it as an application but get nothing when I run it as applet.

Can I put a container in a frame or vice versa?

puredesi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top