When the following class is compiled under Eclipse Europa, jre1.6.0_04, multiple .class files are created and the applet won't load on a webpage unless all of them are present. The class files created are:
TemplateDesigner.class
TemplateDesigner$1.class
TemplateDesigner$2.class
TemplateDesigner$3.class
What's the reason for this?
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
//Since we're adding a Swing component, we now need to
//extend JApplet. We need to be careful to access
//components only on the event-dispatching thread.
public class TemplateDesigner extends JApplet {
JPanel mainPanel, extraPanel;
public void init( ) {
//Execute a job on the event-dispatching thread:
//creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (Exception e) {
System.err.println("createGUI didn't successfully complete");
}
addItem(false, "initializing... ");
}
private void createGUI() {
mainPanel = new BasicTicketTemplate();
extraPanel = new JPanel();
setLayout(new java.awt.GridBagLayout());
add(mainPanel);
}
public void start() {
addItem(false, "starting... ");
}
public void stop() {
addItem(false, "stopping... ");
}
public void destroy() {
addItem(false, "preparing for unloading...");
cleanUp();
}
private void cleanUp() {
//Execute a job on the event-dispatching thread:
//taking the text field out of this applet.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
remove(mainPanel);
}
});
} catch (Exception e) {
System.err.println("cleanUp didn't successfully complete");
}
mainPanel = extraPanel = null;
}
private void addItem(boolean alreadyInEDT, String newWord) {
if (alreadyInEDT) {
addItem(newWord);
} else {
final String word = newWord;
//Execute a job on the event-dispatching thread:
//invoking addItem(newWord).
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
addItem(word);
}
});
} catch (Exception e) {
System.err.println("addItem didn't successfully complete");
}
}
}
//Invoke this method ONLY from the event-dispatching thread.
private void addItem(String newWord) {
System.out.println(newWord);
}
}