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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:54:36+00:00 2026-06-05T06:54:36+00:00

I was working on this drawing program project, (more like, extending it) and I

  • 0

I was working on this drawing program project, (more like, extending it) and I came upon a nasty bug. I added a JLabel on a JPanel, on the South of the BorderLayout, but not only it does not get added into the south of the JPanel, it also gets blurry after I paint something on the JPanel. What I do not understand is why these two things are happening.

Code of the Class:

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Painter extends JPanel{

private int pointCount = 0; // count the number of points

// array of 10000 java.awt.Point references
private Point[] points = new Point[10000];
JLabel myCount = new JLabel();

// set up GUI and register mouse event handler
public Painter() {

    myCount.setText("Points so far: " + pointCount);
    add(myCount, BorderLayout.SOUTH);

    // handle frame mouse motion event
    addMouseMotionListener(
            new MouseMotionAdapter() { // anonymous inner class
                public void mouseDragged(MouseEvent event) {
                    if (pointCount < points.length) {
                        points[pointCount] = event.getPoint(); // find the point
                        ++pointCount; // increment number of points in the array
                        repaint();
                        myCount.setText("Points so far: " + pointCount);
                    } // end if     
            } // end of mouseDragged method
        } // end anonymous inner class
    ); // end of addMouseMotionListener
}// end Painter constructor

// draw ovals in a 4-by-4 bounding box at specified locations on window
public void paintComponent(Graphics g) {
    super.paintComponents(g); // clears drawing area

    // draw all points in the array
    for (int i = 0; i < pointCount; i++) {
        g.fillOval(points[i].x, points[i].y, 12, 12);
    } // end for loop
} // end method paintComponent
} // end of Painter class
  • 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-05T06:54:38+00:00Added an answer on June 5, 2026 at 6:54 am

    First problem can be solved by calling setLayout(new BorderLayout); as the first line of your constructor

    2nd problem can be solved by removing the ‘s’ from paintComponents and just calling paintComponent

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

Sidebar

Related Questions

I have this working great, but I'd like a deeper understanding of what is
I am working on a drawing program and am trying to figure out the
I have been working on this frustrating bug for a few days now and
I'm trying to make a working program from this example: http://msdn.microsoft.com/en-us/library/ms741870.aspx . I think
I am tired of working this out myself , i cannot understand the way
i am new in programming under linux and trying to get working this code:
I'm a LAMP guy and ended up working this small news module for an
I do not get the last version of node-http-proxy working (this used to work
I this working Ruby code that i want to make an executable from with
Had this working; at one stage. The problem is the following text is now

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.