HTML does not display my Java Applet with a JLabel

送分小仙女□ 提交于 2020-01-11 12:03:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!