0

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;

    }

}
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by peter_budo
0

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.

Attachments Output.jpg 15.66 KB
1

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

Edited by Muralidharan.E: n/a

0

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.....

1

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.