简体   繁体   中英

Eclipse ignores applet code

Trying to write and run applets in Java using Eclipse Neon. Here is a very simple example from Schildt (2012):

import java.awt.*;
import java.applet.*;
/*
<applet code="SimpleApplet" width=200 height=60>
</applet>
*/
public class SimpleApplet extends Applet{

    public void paint (Graphics g) {
        g.drawString("Simple Applet Test", 20, 60);
    }

 }

Now, Eclipse does start the applet, but ignores the html applet code inserted under comment. In the example above it disregards the height and width; in other examples it is indifferent to any applet parameter between /* and */. When I run the same class in Linux terminal using appletviewer , everything is fine.

In case anyone is wondering why I want to learn applets ("in 2016"), that's because Schildt said to do so first, and I trust him because his book has been quite helpful so far. Thanks in advance for bona fide help.

Open Run -> Run configurations... -> Java Applet -> Simple Applet . Switch to the second tab Parameters . You'll see there that Width and Height are defined by default to 200. Unfortunately Eclipse ignores the comment tags while creating the configuration with defaults. You can change the values there and they will be applied regardless how you run the applet (ie with shortcut or from the menu).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM