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

  • SEARCH
  • Home
  • 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 8013383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:37:08+00:00 2026-06-04T19:37:08+00:00

My problem is that when trying to set the background color in a JApplet

  • 0

My problem is that when trying to set the background color in a JApplet i’m trying to create, i am unable to get any color other than the default gray.

I would really appreciate it if someone was able to not only tell me whats wrong but also explain it. This technique was learned through a textbook and so, i want to understand the problem so that i know what is going on.

Any and all help is appreciated.

Thank you in advance,

SDG

public class QuoteApplet extends JApplet
{

    public void paint (Graphics appPage)
    {
        setBackground(Color.YELLOW);

        appPage.drawRect(65,55,255,100);
        //page.drawRect(60,80,225,30);
        //page.drawOval(75,65, 20, 20);
        appPage.drawLine(30,30,30,100);
        appPage.drawLine(40,30,40,100);
        appPage.drawLine(55,45,15,85);

        appPage.drawString("There once lived a man named Oedipus Rex.", 70, 70);
        appPage.drawString("You may have heard about his odd complex.", 70, 90);
        appPage.drawString("His name appears in Freud's index,", 70, 110);
        appPage.drawString("'cause he loved his mother.", 70, 130);
        appPage.drawString("-Tom Lehrer", 200, 150);
    }
}
  • 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-04T19:37:10+00:00Added an answer on June 4, 2026 at 7:37 pm

    You want to set the background color of the applet’s contentPane, not the applet itself. So call getContentPane().setBackground(...). And you don’t want to do this from within the paint method. Instead do it in init(). In fact, it is rare that you’ll ever want to override a JApplet’s paint method, and certainly not here. You’re much better drawing in the paintComponent(...) method of a JPanel or other class that derives from JComponent and then adding that to the contentPane, or using it as the contentPane.

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

Sidebar

Related Questions

Im trying to set the background color of a div tag that resides in
I'm trying to set the background color of an ImageView over a specified amount
Here is the problem that I am trying to solve. I have two folders
So we have this problem that we are trying to figure out. Heres what
My problem is that Backbone is trying to do an HTTP request on a
My problem is that I'm trying to count which tag has been used most
I'm trying to solve a problem that anonymous functions make much, much easier, and
I am having problem that when i am trying to submit the form by
I have a problem that I can't seem to figure out. I'm trying to
I've got a problem that I'm stuck on for days now... I'm trying to

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.