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 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

Ask A Question

Stats

  • Questions 287k
  • Answers 287k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For the best performance I would create a single static… May 13, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer Following post will help you understand the difference and issues… May 13, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer My best defensive pointer strategy: Strongly avoid using more than… May 13, 2026 at 5:05 pm

Related Questions

I cannot get this method to return YES: - (BOOL) writeToPasteBoard:(NSString *)stringToWrite { return
I cannot get this simple piece of code to compile without including the TestClass.cpp
I cannot get this to work. I want to use str_to_date to convert a
I cannot get this to work. I have opened a SQL Server Express table
I know this is embarrassing easy but I cannot get this to work right

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.