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

The Archive Base Latest Questions

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

I’m working on my first java project, and I’ve been confounded. This opens a

  • 0

I’m working on my first java project, and I’ve been confounded. This opens a dialog box to get a number from 0-255, checks that it is an integer and that it is in range, then uses the int to make a shade of gray for the background of a graphic applet. I have it doing everything it’s supposed to! But it doesn’t draw the applet. The program is terminated after the last time JOptionPane is called.

import javax.swing.JApplet;
import javax.swing.JOptionPane;
import java.awt.Graphics;
import java.awt.Color;

@SuppressWarnings("serial")
public class DrawingShapes extends JApplet
{
  private Shade shade = new Shade();
  private void getColor()
  {
    int rgb = 0;
    boolean useful = false;
    String number = JOptionPane.showInputDialog("Make this easy for me.\n"
    + "Type an integer between 0 and 255");
    {
      try
      {
        rgb = Integer.parseInt(number);
        if (rgb > 0 && rgb < 255)
        {
          useful = true;
          shade.setColor(rgb);
        }
        else
        {
          useful = false;
          number = JOptionPane.showInputDialog( null, "\"" + number + "\""
          + " is not between 0 and 255!\n"
          + "Lrn2 be doin' it right!" );
        }
      }
      catch (NumberFormatException nfe)
      {
      number = JOptionPane.showInputDialog(null, "\"" + number + "\""
      + " is not an integer!\n"
      + "Lrn2 be doin' it right!");
      }
    }
    if (useful)
    {
      JOptionPane.showMessageDialog(null, rgb + " will be the shade of gray.");
      //WHEN this message is closed, the program seems to quit.
      //System.exit(0);
    }
  }
  public static void main(String[] args)
  {
    new DrawingShapes().getColor();
  }
  public class Shade
  {
    private int color;
    public void setColor(int col)
    {
      color = col;
      System.out.println("color: " + color);
      System.out.println("col: " + col); //IT prints these lines....
    }
    public void paint (Graphics g) //Everything after this is sadly ignored.
    {
      int size = 500;
      setSize(size, size);
      int rgb = color;
      Color gray = new Color(rgb,rgb,rgb);
      setBackground(gray);
      System.out.println(rgb + " This should be the third time");
      g.drawOval(0, 0, size, size);
    }
  }
}

I cannot figure out what is wrong with ‘public void paint (Graphics g)’, but it doesn’t cause anything to happen. I’ll welcome correction from anyone, I’m sure I’ve made a laughable mistake because I’m not quite comfortable with the language…

  • 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:14+00:00Added an answer on June 10, 2026 at 5:18 pm

    This isn’t an applet program — yes, it extends JApplet, but there’s no init method and instead you have a main method — a method that will not be called in an applet program. Please go through the JApplet Tutorial first before doing anything else.

    Other suggestions:

    • Again you’ll need a proper init() override.
    • Don’t draw directly in a JApplet or any top level Window component.
    • Instead draw in the paintComponent(...) method of a JPanel that is shown in the JApplet.
    • Don’t set background colors or change the GUI’s state in the paint(...) or paintComponent(...) method.
    • You’ll want to call the super.paintComponent(...) method inside of your paintComponent(...) method override, and often this is the first method call of your method.
    • Also you’ll want to read the Swing Graphics tutorial on the same site as it will help you a lot.
    • If instead of an applet you wish to create a desk-top application, then place your your attack will be a little bit different in that you won’t have an init() method override, you will need a main method, and you’ll put your components into a JFrame as your top-level Window.
    • To get better help, post less excuses and apologies in your question (I’ve deleted most) and instead focus on providing helpful information in as clear a manner as possible. We aren’t interested in your situation as much as we are interested in helping solve your problem, so please help us help you.

    Luck!

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.