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 8549189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:40:11+00:00 2026-06-11T13:40:11+00:00

I have to create an applet. The code I have written is as follows.

  • 0

I have to create an applet. The code I have written is as follows.

import java.awt.event.*;

import java.awt.*;

import javax.swing.*;

public class feedback extends JApplet

    implements ActionListener
{
    private JTextField login;

    private JTextField email;
    private JTextField comments;
    private final String SUBMIT="SUBMIT";
    private final String CLEAR="CLEAR";
    public void actionPerformed(ActionEvent e)
    {
        String command = e.getActionCommand();
        if(CLEAR.equals(command))
            {login.setText(" ");
            email.setText(" ");
            comments.setText(" ");}
        else if(SUBMIT.equals(command))
           {
            login.setText(" ");
            email.setText(" ");
            comments.setText(" ");
           }
        }
     public void start()
    {
        Container contentPane = getContentPane();
        JScrollPane sPane = new JScrollPane();
        JPanel pContPanel = new JPanel();

        pContPanel.setLayout(new GridBagLayout());

        GridBagConstraints gbc = new GridBagConstraints(3, 4, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10,10,10,10), 20, 20);

        JLabel title = new JLabel("FEEDBACK");
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 3;
        pContPanel.add(title, gbc);

        JPanel panel1 = new JPanel();
        JLabel prompt = new JLabel("LOGIN");
        panel1.add(prompt, gbc);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 1;
        pContPanel.add(panel1, gbc); 

        login = new JTextField(15);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.gridwidth = 2;
        pContPanel.add(login, gbc);

        JPanel panel2=new JPanel();
        JLabel print = new JLabel("EMAIL");
        panel2.add(panel2);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.gridwidth = 1;
        pContPanel.add(panel2, gbc);

        email = new JTextField(30);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.gridwidth = 2;
        pContPanel.add(email, gbc);

        JPanel panel3=new JPanel();
        JLabel ask = new JLabel("COMMENTS");
        panel3.add(panel3);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.gridwidth = 1;
        pContPanel.add(panel3, gbc);

        comments = new JTextField(50);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 1;
        gbc.gridy = 3;
        gbc.gridwidth = 2;
        pContPanel.add(comments, gbc);

        JButton bSUBMIT = new JButton(SUBMIT);
        bSUBMIT.addActionListener(this);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.gridwidth = 1;
        pContPanel.add(bSUBMIT, gbc);

        JButton bCLEAR = new JButton(CLEAR);
        bCLEAR.addActionListener(this);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 1;
        gbc.gridy = 4;
        pContPanel.add(bCLEAR, gbc);


         sPane.setViewportView(pContPanel);
         contentPane.add(sPane, BorderLayout.CENTER);
        }
    }

It is being compiled with NO syntax errors.
But, when I run it using an applet viewer(in BlueJ), it says,

exception: java.lang.IllegalArgumentException : adding container’s parent to itself.

Can you please help me figure out where is the mistake in my code and in what way can I rectify it?
Thank you.

  • 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-11T13:40:13+00:00Added an answer on June 11, 2026 at 1:40 pm

    You are trying to add a panel to itself e.g. panel2.add(panel2);

    the correct program should be :

    import java.awt.event.*;
    
    import java.awt.*;
    
    import javax.swing.*;
    
    public class Feedback extends JApplet implements ActionListener
    {
        private JTextField login;
    
        private JTextField email;
        private JTextField comments;
        private final String SUBMIT="SUBMIT";
        private final String CLEAR="CLEAR";
        public void actionPerformed(ActionEvent e)
        {
            String command = e.getActionCommand();
            if(CLEAR.equals(command))
                {login.setText(" ");
                email.setText(" ");
                comments.setText(" ");}
            else if(SUBMIT.equals(command))
               {
                login.setText(" ");
                email.setText(" ");
                comments.setText(" ");
               }
            }
         public void start()
        {
            Container contentPane = getContentPane();
            JScrollPane sPane = new JScrollPane();
            JPanel pContPanel = new JPanel();
    
            pContPanel.setLayout(new GridBagLayout());
    
            GridBagConstraints gbc = new GridBagConstraints(3, 4, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10,10,10,10), 20, 20);
    
            JLabel title = new JLabel("FEEDBACK");
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.gridwidth = 3;
            pContPanel.add(title, gbc);
    
            JPanel panel1 = new JPanel();
            JLabel prompt = new JLabel("LOGIN");
            panel1.add(prompt, gbc);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 0;
            gbc.gridy = 1;
            gbc.gridwidth = 1;
            pContPanel.add(panel1, gbc);
    
            login = new JTextField(15);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 1;
            gbc.gridy = 1;
            gbc.gridwidth = 2;
            pContPanel.add(login, gbc);
    
            JPanel panel2=new JPanel();
            JLabel print = new JLabel("EMAIL");
            panel2.add(print);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 0;
            gbc.gridy = 2;
            gbc.gridwidth = 1;
            pContPanel.add(panel2, gbc);
    
            email = new JTextField(30);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 1;
            gbc.gridy = 2;
            gbc.gridwidth = 2;
            pContPanel.add(email, gbc);
    
            JPanel panel3=new JPanel();
            JLabel ask = new JLabel("COMMENTS");
            panel3.add(ask);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 0;
            gbc.gridy = 3;
            gbc.gridwidth = 1;
            pContPanel.add(panel3, gbc);
    
            comments = new JTextField(50);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 1;
            gbc.gridy = 3;
            gbc.gridwidth = 2;
            pContPanel.add(comments, gbc);
    
            JButton bSUBMIT = new JButton(SUBMIT);
            bSUBMIT.addActionListener(this);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 0;
            gbc.gridy = 4;
            gbc.gridwidth = 1;
            pContPanel.add(bSUBMIT, gbc);
    
            JButton bCLEAR = new JButton(CLEAR);
            bCLEAR.addActionListener(this);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 1;
            gbc.gridy = 4;
            pContPanel.add(bCLEAR, gbc);
    
    
             sPane.setViewportView(pContPanel);
             contentPane.add(sPane, BorderLayout.CENTER);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create a Java class extending LinearLayout as shown below public class CustomLinear
I have create a Java class extending LinearLayout as shown below public class News
Please consider the following code fragment: import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.lang.reflect.InvocationTargetException;
I am trying to create a Java applet that animates a BTree. I have
I have create a vcf file that contains contacts by using this code ContentResolver
I can't figure this one out. I have Java code that captures Webcam, it
I have a problem with drawing a polygon in Java applet. I don't understand
I have used the NameAndPassword Auth Plugin sample code from Apple to create my
I'm wanting to convert a Java application that I've written into an applet. The
I have written a simple test case that follows Apple's documentation and I am

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.