applet from my java program ?

R

Rasmus B. Nielsen

Hi





Can I start a applet from my java program (not from a HTML side) ?



And if I can, how do I "start" a applet from main ?



From Rasmus
 
I

Ike

Here's what I do, in EVERY Applet I write, which allows me to run it either
way and to discern how it is being run at runtime -Ike

public class Test extends Applet{

boolean isAnApplet = true; //at runtime, you can look at this to know if
you are running as an Applet or application

public void Test(){}

////////////////////////////////////////////////////////////////////////////
////////////////
//// Put this function in your Applet class to allow it to run as an
application also
// Applet is basically a java.awt.Panel. As such you can treat it like
a normal Panel
public static void main(String []args) {
JFrame mainFrame = new JFrame("TestFront1");
Test applet = new
applet.isAnApplet=false; //VITAL!
applet.init();
applet.start();
mainFrame.getContentPane().add(applet);
mainFrame.setSize(400,400); //width, height
mainFrame.setVisible(true);
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top