问题
When I execute the HTML file associated with my applet, nothing is drawn and the screen is empty. Why does this happen? How do I add a String into the Applet?
Source code for the Java Applet:
package m2mcom.web;
import m2mcom.entities.AutomatedTelnetClient;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;
public class Displaytext extends JApplet {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
AutomatedTelnetClient telnet = new AutomatedTelnetClient();
String answer = telnet.request();
JLabel lbl = new JLabel(answer);
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
来源:https://stackoverflow.com/questions/14524480/html-does-not-display-my-java-applet-with-a-jlabel