Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:47:38+00:00 2026-06-03T19:47:38+00:00

I have created an applet and I am going to access an applet method

  • 0

I have created an applet and I am going to access an applet method from my HTML page on a web project.

Here my applet looks like:

public class MessageApplet extends Applet {

    private Label m_mess;

    public void init()
    {
        setBackground(Color.lightGray);
        setLayout(new BorderLayout());
        m_mess = new Label("MessageApplet is Running...: No Selection Yet", Label.CENTER);
        add(BorderLayout.CENTER, m_mess);
    }

    public void setMessage(String message)
    {
        m_mess.setText("Selection: " + message);
    }
}

And my HTML page looks like:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    <SCRIPT LANGUAGE="JavaScript">
        function selectedCity()
        {
            if(document.CityChoice.City[0].checked == true)
            {
                document.SimpleMessageApplet.setMessage(document.CityChoice.City[0].value);
            }
        }
    </SCRIPT>
</HEAD>

<BODY>
    <b>This is the applet</b>
    <APPLET 
        CODE="MessageApplet.class" 
        NAME="SimpleMessageApplet" 
        WIDTH=350
        HEIGHT=100>
    </APPLET>
    <FORM NAME="CityChoice">
        <input type="radio" name="City" value="Boston" onClick="selectedCity()"> Boston<br>
    </form>
</BODY>

</html>

But when I click radio button my browser hangs and I cannot access the applet method ever.

My applet class is in default directory and HTML is in WebContent folder. What should I change in my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:47:40+00:00Added an answer on June 3, 2026 at 7:47 pm

    The problem is the if statement check:

    document.CityChoice.City[0].checked == true
    

    This is not exactly how it goes with JavaScript since the wrong expression you have there throws an error and it never makes it into the if statement body.

    I removed the if statement and changed the code to something like this:

    function selectedCity()
    {
        document.SimpleMessageApplet.setMessage("Hello");
    }
    

    When I click I see the Hello message fine.

    Change your HTML file content to something like:

    <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
            <title>Insert title here</title>
            <SCRIPT LANGUAGE="JavaScript">
                function selectedCity()
                {
                    var elem = document.getElementById('cityRb');
    
                    if(elem.checked)
                    {
                        document.SimpleMessageApplet.setMessage(elem.value);
                    }
                }
            </SCRIPT></HEAD>
        <BODY >
            <b>This is the Applet</b>
        <APPLET CODE="MessageApplet.class" NAME="SimpleMessageApplet" WIDTH=350 HEIGHT=100 >
        </APPLET >
        <FORM NAME="CityChoice">
            <input type="radio" id="cityRb" name="City" value="Boston" onClick="selectedCity()"> Boston<br>
        </form>
    </BODY >
    </html>
    

    Also adding the full class code:

    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Label;
    
    /**
     *
     * @author hmmmmm
     */
    public class MessageApplet extends Applet {
    
        private Label m_mess;
    
        public void init() {
            setBackground(Color.lightGray);
            setLayout(new BorderLayout());
            m_mess = new Label("MessageApplet is Running...: No Selection Yet", Label.CENTER);
            add(BorderLayout.CENTER, m_mess);
            m_mess.setBackground(Color.red);
        }
    
        public void setMessage(String message) {
            m_mess.setText("Selection: " + message);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have created a Self Signed Applet , but not able to access
I have created an applet to read some info from a file on the
I have created a voice recorder applet. The output sound file will be .wav
I have been working on an iPhone project, where we created all the user
I have a method that is being executed on a background thread. From that
I'm going to be honest and say that I have never deployed an applet,
I have a need to integrate a third-party Java applet into a custom web
I'm going through the TVAnimationGestures example from WWDC 2010. I have a question regarding
I have created an applet for recording sound. It throws an exception when I
I have created an applet jar. That jar contains an images in the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.