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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:18:25+00:00 2026-06-10T17:18:25+00:00

I’ve made a JApplet application which consists of nine buttons. When the applet is

  • 0

I’ve made a JApplet application which consists of nine buttons.

  • When the applet is first launched, it is completely white. If you click on the areas where the buttons are, the button will become visible and will function.

enter image description here

  • 30 seconds after the applet is launched, the buttons become visible, but the background is still white.

enter image description here

  • The main menu should look like this.

enter image description here

Why does the applet not load properly?
The code for the applet is as follows:

ConverterApplet.java:

public class ConverterApplet extends JApplet {

    public void init()
    {
        try{
            SwingUtilities.invokeAndWait(new Runnable(){

                @Override
                public void run() 
                {
                    createGUI();

                }

            });
        }catch(Exception e)
        {
            System.err.println("GUI could not be created.");
        }
    }

    public void start(){}
    public void stop(){}

    public void destroy(){}

    public void paint(java.awt.Graphics g){
        resize(400,400);   
    };

    private void createGUI()
    {
        MainPanel m = new MainPanel();
        getContentPane().add(m,BorderLayout.CENTER); 
    }

}

MainPanel.java:

public class MainPanel extends JPanel implements ActionListener {

    private final static String UNIT_SELECTION_PANEL = "UNIT_SELECTION_CARD";
    private final static String UNIT_CONVERSION_PANEL = "UNIT_CONVERSION_PANEL";    

    JPanel cardPanel;
    private JButton[] UnitButtons;
    private JButton backButton; 
    private CardLayout cardLayout;
    private UnitConversionPanel unitConversionPanel;

    public MainPanel()
    {
        super(new GridBagLayout());

        cardPanel = new JPanel();
        JPanel unitSelectionPanel = new JPanel();

        backButton = new JButton("<-");
        backButton.addActionListener(this);
        backButton.setVisible(false);

        UnitButtons = new JButton[9];
        UnitButtons[0] = new JButton("Length");
        UnitButtons[1] = new JButton("Time");
        UnitButtons[2] = new JButton("Mass");
        UnitButtons[3] = new JButton("Speed");
        UnitButtons[4] = new JButton("Volume");
        UnitButtons[5] = new JButton("Area");
        UnitButtons[6] = new JButton("Pressure");       
        UnitButtons[7] = new JButton("Temperature");
        UnitButtons[8] = new JButton("Energy");

        for(int i=0;i<UnitButtons.length;i++)
        {
            UnitButtons[i].addActionListener(this);
        }

        GridLayout layout = new GridLayout(0,3,20,20);
        unitSelectionPanel.setLayout(layout);

        for(JButton buttons: UnitButtons)
        {
            unitSelectionPanel.add(buttons);
        }

        unitConversionPanel = new UnitConversionPanel();

        cardLayout = new CardLayout();
        cardPanel.setLayout(cardLayout);
        cardPanel.add(UNIT_SELECTION_PANEL, unitSelectionPanel);
        cardPanel.add(UNIT_CONVERSION_PANEL, unitConversionPanel);
        cardLayout.show(cardPanel, UNIT_SELECTION_PANEL);

        GridBagConstraints c = new GridBagConstraints();
        //c.fill = GridBagConstraints.VERTICAL;
        c.gridx = 0;
        c.gridy = 0;
        //c.insets = new Insets(5,5,5,5);
        add(backButton,c); 

        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1;
        c.weighty = 1;
        c.gridx = 0;
        c.gridy = 1;
        c.gridwidth=2;
        c.gridheight=1;
        add(cardPanel,c);       
    }

}
  • 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-10T17:18:27+00:00Added an answer on June 10, 2026 at 5:18 pm
    public void paint(java.awt.Graphics g){ 
        resize(400,400); 
    }; 
    

    Don’t call methods that change the GUI in paint, doing so would typically trigger a repaint, which in turn would call paint, which in turn would set a size, which in turn..

    Also, don’t try to resize an applet from within Java code (ever). An applet size should be set in the HTML. Remove that entire method. Be sure to call validate() after the components are added.

    ..hoping to make this .. executable jar. Should I be using a JFrame instead?

    Yes, definitely.

    Then launch the JFrame from a link using Java Web Start. Creating a ‘double click – launch’ app. provides an OK experience for the end user, but JWS makes it all very slick and professional.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group

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.