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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:27:23+00:00 2026-06-14T15:27:23+00:00

I have a Java application containing five buttons: i) Square ii) Rectangle iii) Circle

  • 0

I have a Java application containing five buttons:

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

Clicking on any of the four buttons will result in the respective shape being drawn on the drawing canvas. This is the code used to draw the shape:

The drawing canvas class inherits from JPanel. The shapes which are clicked by the user and are drawn to the drawing canvas are stored in an ArrayList called Shapes.

Now in the drawing canvas class I have a number of mouse listeners. In the MousePressed Event, I want to detect what was clicked.

This is what I used for the buttons:

The naming of the buttons was achieved using the setName method of the JButton class.

However, the Graphics class does not have such a method. How can I detect that one of the shapes has been clicked on the canvas please (once it has been drawn)?

  • 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-14T15:27:24+00:00Added an answer on June 14, 2026 at 3:27 pm

    To keep track of what was drawn, you should keep track of the coordinates of the shapes being drawn into the canvas in a Collection such as an ArrayList and do a check based on this array to the mouse location of the click.

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

Sidebar

Related Questions

I have a java application 'JA' and a Java project containing a servlet project
I have a java application that reads a resource folder containing a bunch of
We have a distributed application containing C++ and Java modules, interacting via CORBA. Are
I have a Java Program containing a class Application inheriting from JFrame. I want
I have a Java web application. Inside the WAR I have a folder containing
I have Java application which sends pointer to function (callback) to some native dll
I have a Java application that run as a background service, i.e. no GUI.
I have a java application where main class is dependent with some other classes.
I have my java-written application being killed after some time of work. Java application
I have a java application which needs to read and write files to HDFS.

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.