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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:10:12+00:00 2026-05-13T14:10:12+00:00

I cannot get this oval to draw on the JFrame. static JFrame frame =

  • 0

I cannot get this oval to draw on the JFrame.

static JFrame frame = new JFrame("New Frame");
public static void main(String[] args) {
  makeframe();
  paint(10,10,30,30);
}

//make frame
public static void makeframe(){
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  JLabel emptyLabel = new JLabel("");
  emptyLabel.setPreferredSize(new Dimension(375, 300));
  frame.getContentPane().add(emptyLabel , BorderLayout.CENTER);
  frame.pack();
  frame.setVisible(true); 
}

// draw oval 
public static void paint(int x,int y,int XSIZE,int YSIZE) {
  Graphics g = frame.getGraphics();
  g.setColor(Color.red);
  g.fillOval(x, y, XSIZE, YSIZE);
  g.dispose();
}

The frame displays but nothing is drawn in it. What am I doing wrong here?

  • 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-05-13T14:10:12+00:00Added an answer on May 13, 2026 at 2:10 pm

    You have created a static method that does not override the paint method. Now others have already pointed out that you need to override paintComponent etc. But for a quick fix you need to do this:

    public class MyFrame extends JFrame {  
       public MyFrame() {
            super("My Frame");
    
            // You can set the content pane of the frame to your custom class.
            setContentPane(new DrawPane());
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(400, 400);
            setVisible(true); 
       }
    
       // Create a component that you can actually draw on.
       class DrawPane extends JPanel {
            public void paintComponent(Graphics g) {
                g.fillRect(20, 20, 100, 200); // Draw on g here e.g.
            }
       }
    
       public static void main(String args[]){
            new MyFrame();
       }
    }
    

    However, as someone else pointed out…drawing on a JFrame is very tricky. Better to draw on a JPanel.

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

Sidebar

Related Questions

I cannot get this to work properly, I need the program to list through
I cannot get this working correctly, actually at all. What I have so far
A daft question, but I really cannot get this to work: I have some
I have now tried to get this to work for a few hours but
I have searched and tried a number of things for this, but simply cannot
I'm trying to use the new event log API to get the oldest record
How can you blit a non-rectangular (e.g. oval) part of a bitmap into a
I have a url which will take the following form: /AuditReview/Review/15d49a66-5c11-492c-921f-9e1700bd2618 I cannot get
I'm using GAPI to try and create simple reports from our Google Analytics data.
Is it possible to call a PHP function found in a file on another

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.