I'm trying to write an applet with menus but is not working
I'm getting these errors:

load: MenuFrame$AppletMenu.class can't be instantiated.
java.lang.InstantiationException: MenuFrame$AppletMenu
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

could some one please explain me what is wrong.
also i noticed that the value of many local variables is not used but don't know why or how to fix it.

here is my code:

import java.applet.Applet;
import java.awt.Event;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;

 <applet code="AppletMenu" width=250 height=250>

class MenuFrame extends Frame {

        public MenuFrame(String title) {

        MenuBar mbar = new MenuBar();
        Menu archivo = new Menu("Archivo");
        MenuItem nuevo, salir, item1;
        archivo.add(nuevo = new MenuItem("Nuevo"));
        Menu submenu = new Menu("Submenú Guardar");

        MenuItem guardar, guardarComo;
        submenu.add(guardar = new MenuItem("Guardar"));
        submenu.add(guardarComo = new MenuItem("Guardar Como"));

        archivo.add(item1 = new MenuItem("-"));
        archivo.add(salir = new MenuItem("Salir"));

        Menu menuAyuda = new Menu("Ayuda");
        MenuItem acercaDe, ayuda;
        menuAyuda.add(acercaDe = new MenuItem("AcercaDe"));
        menuAyuda.add(ayuda = new MenuItem("Ayuda"));


    public boolean handleEvent(Event evt) {
        // Si la ventana se cerró salir de la aplicación
        if (Event.WINDOW_DESTROY == evt.id && this == evt.target)
        // Si el evento es del tipo ACTION_EVENT?
        switch (evt.id) {
        case Event.ACTION_EVENT: {
            if (evt.target instanceof MenuItem) {
                if ("Nuevo".equals(evt.arg))
                    System.out.println("archivo -nuevo-");
                if ("Guardar".equals(evt.arg))
                    System.out.println("archivo -guardar-");
                if ("Guardar Como".equals(evt.arg))
                    System.out.println("archivo -guardar como-");
                if ("AcercaDe".equals(evt.arg))
                    System.out.println("menu ayuda -AcercaDe-");
                if ("Ayuda".equals(evt.arg))
                    System.out.println("menu ayuda -ayuda-");
            // Si la opción seleccionada es Salir terminar la aplicación
            if ("Salir".equals(evt.arg))
        return true;

    public class AppletMenu extends Applet {
        MenuFrame menu;

        public void init() {
            menu = new MenuFrame("Applet Menu");

        public void start() {


        public void stop() {

I compiled your code at first i got the errors you have described, so i took some parts and re compiled one by one .. Your code is o.k it works.

could you please explain me how did you manage to make it work ?

as i couldn't make it work i wrote it again but in a different way and made it work but i'm not quite happy that i couldn't understand what was wrong with the one i posted here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.