I am trying to wrap my head around the rules of applet use. I realize that an applet does not have to have a main method (it can use init()
instead) but every code sample my professor provides is an applet with a main method, like in the code below.
My understanding was that it is not a good idea to have a main method in an applet because of security issues, is this correct? When (if ever) should I use a main method in an applet?
Also, my professor is using applets like this embedded into a PowerPoint presentation which he can then run easily during his presentation. Would it still be possible to run an applet like this which was embedded into a PowerPoint presentation if the applet used inti()
instead of main()
? I ask that because I cannot see any reason why he would use a main method in such an applet unless it was required for the applet to run properly when embedded into a PowerPoint presentation.
//EventDispatcherThreadDemo.java
import javax.swing.*;
public class EventDispatcherThreadDemo extends Japplet{
public EventDispatcherThreadDemo(){
add(new JLabel("Hi, it runs from an event dispatch thread"));
}
public static void main(Stirng[] args){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
JFrame frame = new JFrame("EventDispatcherThreadDemo");
frame.add(new EventDispatcherThreadDemo());
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
P.S. This has nothing to do with homework, just trying to learn more about applets.