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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:33:00+00:00 2026-06-01T13:33:00+00:00

when i right click on the the Jframe this pie appears. what i want

  • 0

when i right click on the the Jframe this pie appears. what i want is to calculate the angle of each pie when click event occurs.

 Color[] c = {Color.BLACK, Color.RED, Color.BLUE, Color.YELLOW, 
                     Color.GREEN, Color.CYAN, Color.MAGENTA, Color.PINK};
        for(int i=0; i<8; ++i){
            g.setColor(c[i]);
            g.fillArc(x, y, w, h, i*45, 45);
        }

here what i have tried

  public void mouseClicked(MouseEvent e) 
        {


              PointerInfo a = MouseInfo.getPointerInfo();
               Point d  = a.getLocation();
               x1 = (int)d.getX();
               y1 = (int)d.getY();
               int base=x1-CenterX;
               int prep=CenterY-y1;
               double tan=prep/base;
               double angle=Math.atan( tan);
  }

but the calculted angle is not correct. it some times give me divide by zero exception.
and here is my right click event which shows the menu.

  public void mousePressed(MouseEvent e) {
            if(e.isPopupTrigger())
            {
                CenterX=e.getX();
                CenterY=e.getY();
              try {
                    Thread.sleep(300L);
                } catch (InterruptedException ex) {
                    Logger.getLogger(animate.class.getName()).log(Level.SEVERE, null, ex);
                }
        p.repaint();
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if(e.isPopupTrigger()){
               s=e.getX();
                as=e.getY();
                p.mx=e.getX(); 
        p.my=e.getY();
  • 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-01T13:33:01+00:00Added an answer on June 1, 2026 at 1:33 pm

    Yes, a divide by zero will happen if base == 0, ie if x1 == CenterX.

    use Math.atan2. It converts x/y coordinates to angles and takes care of all of the messy math for you.

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

Sidebar

Related Questions

Is right click a Javascript event? If so, how do I use it?
I want to add right click menu items to the explorer (i.e. when you
With the above code i want to close the popup right after click on
I have a right click popup menu that works fine. I now want to
This happens until I right-click and open the file once by selecting Open with
Event though a right-click (as far as I know) fires a mousedown event, that
I want to simulate the Right click/Update service reference command in a VS2010 addin.
Short: I need a right-click event to highlight the cell row. I am using
When I right click on the database I want to export data from, I
When I right-click on my project in Eclipse, and select Externalize Strings the wizard

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.