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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:53:52+00:00 2026-06-15T04:53:52+00:00

I have a problem with put drawn circle into middle of Frame by using

  • 0

I have a problem with put drawn circle into middle of Frame by using methods getWidth() and getHeight(). I tried something with Image package but no idea where to implement this methods:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Frame;
import java.awt.Image;

public class Circle extends Frame {

public Circle() {

    setSize(400,400);
    setLocationRelativeTo(null);
    setVisible(true);
}

public Color() {
}

public void paint(Graphics g) {

    g.setColor(Color.ORANGE);
    g.fillOval(200, 200, 200, 200);
}

public static void main(String[] args) {

    Circle c = new Circle();

    c.paint(null);
}
}

Then I have to use method setColor(Color) and Color class constructor to make random color of this circle (after every run of this program). I opened Color constructor but there is an error :/

  • 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-15T04:53:54+00:00Added an answer on June 15, 2026 at 4:53 am

    Better to extract all the paint functionality to a JComponent here to take full advantage of Swing’s optimized paint model using paintComponent.

    The Circle is actually a JFrame. Inside in its constructor, a new component is created which handles the painting of the circle. The Color constructor has been removed as this is invalid syntax.

    The circle co-ordinates are start in the top left-hand corner and take the full available width & height for drawing.

    Also would recommend using lightweight Swing components over old-style AWT component.

    public class Circle extends JFrame {
    
        public Circle() {
            setSize(400, 400);
            add(new CirclePanel());
            setLocationRelativeTo(null);
            setVisible(true);
        }
    
        public static void main(String[] args) {
            Circle c = new Circle();
        }
    }
    
    class CirclePanel extends JComponent {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.ORANGE);
            g.fillOval(0, 0, getWidth(), getHeight());  
        }
    }
    

    See: Painting in AWT and Swing

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

Sidebar

Related Questions

Hello I have problem to put together animations of two separate objects to second
Basically i have a problem with this timer program I am trying to put
I have put a web view inside a uitableviewcell Problem : didSelectRowAtIndexPath is not
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with UIWebView delay when the load image from url. In my
I have problem while loading data into html select when users press or click
I have a problem using opengl on android to draw a simple rectangle. This
I have ran into a problem that i suspect has to do painting/drawing elements
My problem is I have paths to draw cities and I want to put
I am using CATiledLayer as backing layer for my UIView, which I have put

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.