Results 1 to 5 of 5
  1. #1
    kusuma is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default using menu concept

    Hi.....! this prg is sucessfully compiled b't the prb is after runing the prg am geting the follwing error as.....


    Exception in thread main java .lang.noSuchMethod Error:main
    please heip me out...advance thank u...:)



    import java.applet.Applet;

    import java.awt.Dimension;

    import java.awt.Frame;

    import java.awt.Graphics;

    import java.awt.Menu;

    import java.awt.MenuBar;

    import java.awt.MenuItem;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import java.awt.event.ItemEvent;

    import java.awt.event.ItemListener;

    import java.awt.event.WindowAdapter;

    import java.awt.event.WindowEvent;



    /*

    <applet code="MenuDemo" width=200 height=200>

    */

    class MenuFrame extends Frame {

    String msg = "";



    MenuFrame(String title) {



    MenuBar mbar = new MenuBar();

    Menu Package = new Menu("Package");

    MenuItem item1, item2;

    Package.add(item1 = new MenuItem("Active"));

    Package.add(item2 = new MenuItem("Passive"));

    Menu sub1 = new Menu("Active");

    MenuItem item3, item4, item5;

    sub1.add(item3 = new MenuItem("Condutors"));

    sub1.add(item4 = new MenuItem("inductors"));

    sub1.add(item5 = new MenuItem("resistors"));

    Package.add(sub1);

    Menu sub2 = new Menu("Passive");

    MenuItem item6, item7, item8, item9, item10;

    sub2.add(item6 = new MenuItem("Digitalizers"));

    sub2.add(item7 = new MenuItem("Analogic"));

    sub2.add(item8 = new MenuItem("Transmittor"));

    sub2.add(item9 = new MenuItem("MOSFET"));

    sub2.add(item10 = new MenuItem("Diodes"));

    Package.add(sub2);

    Menu sub3 = new Menu("Resistors");

    MenuItem item11, item12, item13, item14;

    sub3.add(item11 = new MenuItem("DIP"));

    sub3.add(item12 = new MenuItem("1206"));

    sub3.add(item13 = new MenuItem("0805"));

    sub3.add(item14 = new MenuItem("0603"));

    Package.add(sub3);

    MyMenuHandler handler = new MyMenuHandler(this);

    item1.addActionListener(handler);

    item2.addActionListener(handler);

    item3.addActionListener(handler);

    item4.addActionListener(handler);

    item5.addActionListener(handler);

    item6.addActionListener(handler);

    item7.addActionListener(handler);

    item8.addActionListener(handler);

    item9.addActionListener(handler);

    item10.addActionListener(handler);

    item11.addActionListener(handler);

    item12.addActionListener(handler);

    item13.addActionListener(handler);

    item14.addActionListener(handler);

    MyWindowAdapter adapter = new MyWindowAdapter(this);

    addWindowListener(adapter);

    }



    public void paint(Graphics g) {



    }



    class MyWindowAdapter extends WindowAdapter {

    MenuFrame menuFrame;



    public MyWindowAdapter(MenuFrame menuFrame) {

    this.menuFrame = menuFrame;

    }



    public void windowclosing(WindowEvent we) {

    menuFrame.setVisible(false);

    }



    }



    class MyMenuHandler implements ActionListener, ItemListener {

    MenuFrame menuFrame;



    public MyMenuHandler(MenuFrame menuFrame) {

    this.menuFrame = menuFrame;

    }



    public void actionPerformed(ActionEvent ae) {

    String msg = "You selected";

    String arg = ae.getActionCommand();

    if (arg.equals("Active..."))

    msg += "Active.";

    else if (arg.equals("passive.."))

    msg += "Passive.";

    else if (arg.equals("conductors"))

    msg += "conductors.";

    else if (arg.equals("resistors"))

    msg += "resistors.";

    else if (arg.equals("inductors"))

    msg += "inductors.";

    else if (arg.equals("digitalizers"))

    msg += "digitalizers.";

    else if (arg.equals("Analogic"))

    msg += "Analogic.";

    else if (arg.equals("Transmitor"))

    msg += "transimitor.";

    else if (arg.equals("MOSFET"))

    msg += "MOSFET.";

    else if (arg.equals("diodes"))

    msg += "diodes.";

    else if (arg.equals("DIP"))

    msg += "DIP.";

    else if (arg.equals("1206"))

    msg += "1206.";

    else if (arg.equals("0805"))

    msg += "0805.";

    else if (arg.equals("0603"))

    msg += "0603.";

    }



    public void itemStateChanged(ItemEvent ie) {

    menuFrame.repaint();

    }

    }



    public class MenuDemo extends Applet {

    Frame f;



    public void init() {

    f = new MenuFrame("Menu Demo");

    int width = Integer.parseInt(getParameter("Width"));

    int height = Integer.parseInt(getParameter("height"));

    setSize(new Dimension(width, height));

    f.setSize(width, height);

    f.setVisible(true);

    }


    public void start() {

    f.setVisible(true);

    }



    public void stop() {

    f.setVisible(false);

    }

    }

    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    So does your class have a main method? Obviously not. So why doesn't it? Or why are you trying to run it if it doesn't?

  3. #3
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Welcome to the forum, please use code tags when posting code.

    About your OP, it is stating that you are calling a method main that does not exist. Post the complete error message at the line it is referring.

  4. #4
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    @Junky - I think this is an applet. Applet does not or should not have main method.

    I could be wrong, correct me if I am wrong.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    You could be right but OP is trying to run it like it was an app. Hence my second question above.

Similar Threads

  1. Need help in thread concept
    By umapathy_sekar in forum Advanced Java
    Replies: 2
    Last Post: 11-11-2010, 07:25 AM
  2. Fill a menu dynamically when menu is shown
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 05:47 PM
  3. How to use SWT menu and menu event
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 05:46 PM
  4. React to menu action and checkbox menu
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 08:50 PM
  5. Replies: 7
    Last Post: 05-09-2008, 08:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •