Sarah_b Sarah_b - 7 months ago 25
Java Question

Can't add JMenuBar to Applet

I'm trying to add a menu to my

Applet
however I get a compilation error. I can't figure out why. Can someone help me?

import java.applet.*;
import javax.swing.*;
import java.awt.*;
public class app extends Applet {

public void init() {
JMenuBar menuBar = new JMenuBar ();
JMenu menu = new JMenu ("Help");
menuBar.add(menu);
JMenuItem mItem = new JMenuItem ("Log out");
menu.add(mItem);
this.setJMenuBar(menuBar);
}
}

Answer
public class app extends Applet {

    public void init() {
        JMenuBar menuBar = new JMenuBar ();
        JMenu menu = new JMenu ("Help");
        menuBar.add(menu);
        JMenuItem   mItem = new JMenuItem ("Log out");
        menu.add(mItem);
        this.setJMenuBar(menuBar);

That would work but for a J in there to denote a Swing applet.

public class app extends JApplet {

    // ..