Sarah_b
Sarah_b

Reputation: 31

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);
    }
}

Upvotes: 0

Views: 298

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168825

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 {

    // ..

Upvotes: 2

Related Questions