java-17

Applet with JavaSE 17


I studied Java 2 a long time ago and now I would like to create applets for fun. I'm working with Eclipse and I have installed avaSE17 but it seems that the updates of the last few years do not allow importing java.awt.* and java.applet.*.

How can I create applets with java 17?

TY

I hope someone can show me an example. A simple text displayed on a window it will be enough.

TY


Solution

  • The simplest thing to do would be to use swing. This will create an window and does not require a browser.

    import javax.swing.*;
    
    public class TextOnAWindow{
    
        public void createAndShow(){
            JFrame frame = new JFrame("Hello World");
            frame.add(new JLabel("Hello World");
            frame.pack();
            frame.setVisible(true);
        }
        
        public static void main(String[] args){
            SwingUtilities.invokeLater( 
              ()->{
                  new TextOnAWindow().createAndShow();
              });
        }
    
    }
    

    Maybe check a tutorial first to get a better idea. Avoid the netbeans part, unless you want to use netbeans.