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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:52:11+00:00 2026-06-14T21:52:11+00:00

I have a program containing five buttons: i) Square ii) Rectangle iii) Circle iv)

  • 0

I have a program containing five buttons:

i) Square ii) Rectangle iii) Circle iv) Triangle v) Clear

Clicking on any of the first four buttons will draw the respective shape on the drawing canvas using the following code:

The shapes can be dragged. They also should be resized. I was just trying to change the cursor of the mouse around the four edges of the shape (NW, NE, SW, SE). This works fine for squares and rectangles since they have four sides. However, I have some problem implementing the same for the circle and triangle.

This is what I did in my mouseClicked event:

What I want to do is that if the string shape_type contains circle, for example, it draws a border around it so that the user can see the boundaries of the shape.

However, I can’t just use the following code inside the if statement:

How can I draw the border please? Thanks 🙂

  • 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-14T21:52:13+00:00Added an answer on June 14, 2026 at 9:52 pm

    You are correct that you can’t do painting in a MouseListener method. What you can do is set shapeUnderMouse in your mouseClicked method, then call repaint. You’ll get better performance if you only repaint the areas that you know are changing visually, but it’s not strictly necessary.

    The if (shapeUnderMouse != null) block should be placed in your paint method.

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

Sidebar

Related Questions

i have to write a program in C to read a file containing several
So right now I have a program containing a piece of code that looks
I have a java program using objects containing huge arrays of floats. Thing is
We have a product installer created with Wix, containing a program package ( V1
I have a CUDA program containing a host function and a device function Execute()
In my program I have an NSPanel containing a web view appear to a
Hi I have made a program that reads a text file containing words and
I have a simple program which reads a large file containing few million rows,
I have a Java Program containing a class Application inheriting from JFrame. I want
I have this program with a small tank and a black square. The tank

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.