I am working on my java code using combo box.............I compiled it and it says process complete....BUT.....I cannot view it in applet viewer.....whenever I click the play button, it displays "java.lang.NoSuchMethoderror:main" "Exception in thread "main".............

what do these mean???? How can I make it be displayed in the applet viewer??

here is the code....

import java.awt.*;
import java.applet.*;



public class CheckboxApplet extends Applet

{
    Label    label1;

    Checkbox checkbox1;

    Checkbox checkbox2;

    Checkbox checkbox3;



    public void init()

    {
        label1 = new Label("Who is the most beautiful?",0);

        checkbox1 = new Checkbox("Suzumiya Haruhi", null, true);

        checkbox2 = new Checkbox("Nam Gyu Ri", null, false);

        checkbox3 = new Checkbox("Alodia Gosiengfiao", null, false);


        add(label1);

        add(checkbox1);

        add(checkbox2);

        add(checkbox3);

    }



    public void paint(Graphics g)

    {

        Font font = g.getFont();

        FontMetrics fontMetrics = g.getFontMetrics(font);

        int height = fontMetrics.getHeight();



        boolean checked = checkbox1.getState();

        if (checked)

            g.drawString("Suzumiya Haruhi: NO! not me....", 20, 120);

        else

            g.drawString("Suzumiya Haruhi: not selected", 20, 120);



        checked = checkbox2.getState();

        if (checked)

            g.drawString("Nam Gyu RI: Yes it's me! YOU GOT IT!", 20, 120 + height);

        else

            g.drawString("NAm Gyu Ri: not selected", 20, 120 + height);



        checked = checkbox3.getState();

        if (checked)

            g.drawString("Alodia Gosiengfiao: are you kidding? ME?", 20, 120 + 2 * height);

        else

            g.drawString("Alodia Gosiengfiao: not selected", 20, 120 + 2 * height);

    }



    public boolean action(Event evt, Object arg)

    {

        repaint();

        return true;

    }

}

I have copied and pasted your code.. Its working fine..
How do you executing your program, Using eclipse,netbeans or using textpad??
See the attachment.

The action method is depricated...
Can you use ItemListener instead of action?

As follows

import java.awt.*;import java.applet.*; 
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class CheckboxApplet extends Applet implements ItemListener{  
    Label    label1;     Checkbox checkbox1;   
    Checkbox checkbox2;     Checkbox checkbox3;  
    public void init()     {      
        label1 = new Label("Who is the most beautiful?",0);   
        checkbox1 = new Checkbox("Suzumiya Haruhi", null, true);   
        checkbox1.addItemListener(this);
        checkbox2 = new Checkbox("Nam Gyu Ri", null, false);       
        checkbox2.addItemListener(this);
        checkbox3 = new Checkbox("Alodia Gosiengfiao", null, false);     
        checkbox3.addItemListener(this);
        add(label1);         add(checkbox1);         add(checkbox2);    
        add(checkbox3);    
    }   
    
    public void paint(Graphics g)     {  
        Font font = g.getFont();     
        FontMetrics fontMetrics = g.getFontMetrics(font);    
        int height = fontMetrics.getHeight();        
        boolean checked = checkbox1.getState();     
        if (checked)       
            g.drawString("Suzumiya Haruhi: NO! not me....", 20, 120);     
        else             g.drawString("Suzumiya Haruhi: not selected", 20, 120);   
        checked = checkbox2.getState();      
        if (checked)          
            g.drawString("Nam Gyu RI: Yes it's me! YOU GOT IT!", 20, 120 + height);      
        else             g.drawString("NAm Gyu Ri: not selected", 20, 120 + height);      
        checked = checkbox3.getState();     
        if (checked)           
            g.drawString("Alodia Gosiengfiao: are you kidding? ME?", 20, 120 + 2 * height);   
        else            
            g.drawString("Alodia Gosiengfiao: not selected", 20, 120 + 2 * height);     }     
    

    

    public void itemStateChanged(ItemEvent e) {
        repaint();
    }
}

I have copied and pasted your code.. Its working fine..
How do you executing your program, Using eclipse,netbeans or using textpad??
See the attachment.

using JCreator.....

using JCreator.....

Your Applet must have been created in JCreator as Basic Java applet or it will not be run correctly on execution (old article but I think it is still right on execution). Work around can be by managing arguments in tools options as mentioned 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.