简体   繁体   中英

How to use applets in intelliJ?

I'm a java beginner and I wanna know how to use applets. I've got this little test-program for the paint-applet:

import java.awt.*;
import java.applet.*;
public class Main extends Applet {
    public void init() {
    }
    public void paint(Graphics g) {
        setBackground(Color.blue);
        g.setColor(Color.yellow);
        g.drawRect(20, 20, 100, 50);
        g.fillRect(20, 80, 100, 50);
    }
}

But in the IDE, "Applet" in the 3rd line has a stripe through it. And if I try to run the code, I get this error:

Error: Could not find or load main class sun.applet.AppletViewer
Caused by: java.lang.ClassNotFoundException: sun.applet.AppletViewer

I'm using IntelliJ as IDE and use jdk14

Can someone help?

Applets are deprecated since java 9. You should be using java 8 (jdk 14 does not work)

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