Specifying a circle with 2 mouse presses

Hi,
I'm trying to create an applet that allows the user to specify a circle with 2 mouse presses. I'd like the 1st point to represent the circle's centre and the 2nd to be any point on the periphery.
Creating a mouse press event handler is a given obviously within the applet. I think I'm going to need to create a variable to store the count of the mouse presses (i.e. so that I know when there've been two and the circle can be created).
Can anyone tell me what the basic logic would be to actually create the circle based on the 2 mouse presses?
Thanks.

Can anyone tell me what the basic logic would be to
actually create the circle based on the 2 mouse
presses?
implements MouseListener{
  int centerX = 0;
  int centerY = 0;
  int radius = 0;
public void paint(Graphics g){
  g.drawOval(centerX-radius, centerY-radius,
             centerX+radius, centerY+radius);
public void mousePressed(MouseEvent me){
  centerX = me.getX();
  centerY = me.getY();
public void mouseReleased(MouseEvent me){
  //a line from the center
  //length of x
  int x = me.getX()-centerX;
  //length of y
  int y = me.getY()-centerY;
  //a2 + b2 = c2
  radius = sqrt(pow(x, 2)+pow(y, 2));
}i think this will work.. I used mousePressed and mouseReleased instead of two clicks.. but you can alter this if you like of course.. im not that very sure of the radius calculation, but i hope you get my point :)

Similar Messages

  • I can enter a webadress in the adress field but when I hit enter nothing happens, If I press with my mouse on the side for the site to load it loads perfectly but enter pressing is non-responsive

    I can enter a webadress in the adress field but when I hit enter nothing happens, If I press with my mouse on the side for the site to load it loads perfectly but enter pressing is non-responsive
    I use FF4

    Please re-post in the Office for Mac Product Forums hosted by Microsoft.

  • Suddenly my mouse has a green Circle with a Plus sign in the middle?

    Suddenly my mouse has a green Circle with a Plus sign in the middle?

    Thanks Had to close down and it went away, Mail was not responding. forced close and shut down. restarted and OK.

  • Every time I press F6, my backlit keyboard key, a circle with a cross pops up and won't let me turn on my backlit keyboard ??

    Every time I press F6, my backlit keyboard key, a circle with a cross comes on and wont let me turn on or up my light behind my keybored... any ideas ?

    nevermind. your backlit keyboard wont work in a light environment

  • 2013 iMac 27" 3.4GHz Quad-Core Intel Core i7 won't boot. Round circle with line through it.

    Here's my specs:
                PROCESSOR                 065-C0PK  3.4GHz Quad-Core Intel Core i7
                MEMORY                    065-0638  8GB 1600MHz DDR3 SDRAM-2X4GB
                HARD DRIVE                065-C0Q6  3TB Fusion Drive
                GRAPHICS                  065-C099  NVIDIAGeFrc GTX 680MX 2G GDDR5
                MOUSE                     065-0663  APPLE MOUSE
                BATTERY CHARGER           065-0670  NO APPLE BATTERY CHARGER
                PAGES                     065-C13D  NONE
                NUMBERS                   065-C13F  NONE
                KEYNOTE                   065-C13G  NONE
                APPLE KEYBOARD            065-0667  Apple Num Kybd(Eng)+User's Gd
                COUNTRY KIT               065-0718  COUNTRY KIT
    I've only had my new iMac for a week and today when I rebooted I got a gray circle with a line through it. I've already done the command-r and used Disk Utility to Repair Disk and Repair Disk Permissions... over and over. As a last resort I even reinstalled Mountain Lion with the OS X Internet Recover. No such luck. After it still booted with the gray circle with a line through it.
    I was able to use "Scan Image for Restore" to see that all my files are on the hard drive.
    What should I do?

    Thanks for the response, mende1!
    Unfortunately, I also previously tried booting with the Shift key. Nothing. It acted like I wasn't even pressing the Shift key. I tried it multiple times. Sorry, I forgot to say that in my initial post.
    I just tried the Option key and selected Macintosh HD (the only option). I still got the gray circle with the line though it.
    I've already spent at least 30-40 hours installing all my software and transferring over all my pics and music. I can't "erase the disk and install OS X again".

  • How do i run an external monitor with my macbook and change settings so that when i close the lid the signal to the monitor is not lost and i can continue using the mac with a mouse and a wireless keyboard?

    How do i run an external monitor with my macbook and change settings so that when i close the lid the signal to the monitor is not lost and i can continue using the mac with a mouse and a wireless keyboard?

    No, nothing will prevent the computer from going to sleep when you close its display except third-party hacks that are designed to do exactly that. I strongly advise against using any of those, as they may interfere with successful entry into clamshell mode (and they carry other downside risks as well). Just wait until the computer is asleep (with its sleep light pulsing), then press any key on the keyboard. It sounds as though your setup is working as it's designed to do.

  • How can I get mouse pressed and mouse released positions on the desktop whi

    Hello All,
    I am generating a Frame using Swing API. My requirement is I need to capture the mouse pressed and mouse released positions, whenever user drags the mouse on desktop region (i.e. outside of the Frame). I require these points to find the rectangle region user has generated starting from mouse pressed to mouse released position. I need to pass that rectangle to Robot class in order to capture that desktop region.
    Can anybody help me out how can I achieve this using java on MAC, Linux and Windows platforms?
    Thanks in advance.
    Regards,
    VPKVL

    VPKVL wrote:
    DarrylBurke wrote:
    Can't be done in Java.I don't think that there is something which can't be done using java. When searched over net, found few applications which are using java for implementing this feature but not free, asking for license fee. I checked by downloading the demo version.
    Just want to know the hint how it can be achieved so that I can move further on that lines.
    Your thoughts ?They use JNI with the OS API.

  • TS1424 When I click to play my songs in the library they will not play and show a circle with an exclamation point in the middle of it, what does that mean and how can I get them to play?

    When I click to pay my songs in the library they will not play and it shows a circle with an exclamation point within it. What does that mean, how do I fix it, and how will it play my songs again? They used to play before on my Iphone4 with no problem, but since I upgraded to the Iphone4s there is an issue.

    I am having the same problem. I have just tried this. Unplug iphone > open itunes > delete all music from itunes library > close itunes > re-open itunes > add music from original folder > plug in iphone > select songs > press sync > unplug iphone using eject button onscreen > checked phone .... still nothing in music folder on phone. On itunes the "On this iphone" tab the songs remain there but greyed out.

  • Make a circle with outline and image

    Hi All
    I am trying to make an image in the shape of a circle, with a border, kind of like the image attached, but i need the black boarder to be even, and ideally need it to be a template so the circle and boarder is the same size and i just add different images.
    ive looked everywhere and cant find any videos that do this.
    Any help would be really appreciated
    im using cs6 for windows

    Hello,
    Create a new image, for this example I used 600x600 pixels, adjust it as needed.
    Press Crtl + R to enable rulers. (View > Rulers)
    Double click on the background to convert it to a layer.
    Make sure you have View > Snap enabled.
    Press Ctrl + T to enter Transform mode. (Edit > Transform)
    Click on the side ruler and drag a guide until it snaps to center. Click on the top ruler and drag another guide until it snaps to center. Hit enter or escape.
    Select the circular marquee tool, and hold down Shift while dragging to constrain your selection to a circle:
    Press Alt + Backspace to fill the selection with the foreground color.
    Use the move tool to snap the circle to center.
    On the layer pallete, turn Fill to 0%:
    While keeping the circle layer selected, go to fx > Stroke:
    Adjust the size slider to taste and hit OK.
    Create a new layer bellow the circle layer.
    In your layer pallete, hold down Crlt and click on the thumbnail of the circle layer  to load the selection.
    Press Crtl + I to invert the selection. (Select > Inverse)
    Press D then Crtl + Backspace to fill the selection with White.
    Save your template for future use! Now all you have to do is drag your pictures at the bottom of the layer stack:
    Hope this makes sense, please post again if you have any questions.
    have fun!
    EDIT: for some reason charles reply wasn't showing up, sorry.
    also I expected the images to be auto resized?

  • Will only boot to a circle with a slash

    MacBook Pro will only boot to the circle with a slash symbol. I have tried all the turn on hold C, X, Option key suggestions and have tried the clearing ideas (hold cntl, commmd, p, r). Have put the system disk in to boot from that, now I cannot get the disk out.
    Any suggestions out there?

    Your computer is not recognizing your hard drive. Plug a mouse in and hold the mouse key down when booting. The disc should eject. Next, make sure the disc is real clean with no finger prints or scratches on it. Then try booting from it again (by holding the "C" key down) when booting. See if your Disk Utility sees the drive and run that. If it does not, or the unit will not boot from the install disc, then you have a serious problem--possibly logic board-related. You could also try running DiskWarrior and see if that will boot and repair the drive.
    Dave M.
    MacOSG Founder/Ambassador  An Apple User Group  iTunes: MacOSG

  • What does the little circle with a line in it mean when in edit mode? how can I get rid of it?

    What does a little circle with a line in it mean when I am trying to edit? how do I get rid of it?

    robynlwitheridge
    What version of Premiere Elements are you using and on what computer operating system is it running?
    From your description "little circle with a line in it", that sound like a symbol when you are trying to do a cannot do operation.
    What exactly are you doing in your edit activities when you see this circle with a line in it? Is it at the end of the mouse cursor?
    Can you post a screenshot of it?
    If my first impression of what this is happens to be correct, then "How do I get rid of it?" answer comes from
    a. defining what you want to do
    and
    b. correcting any mis-steps you are taking in doing that
    We will be watching for your follow up.
    Thanks.
    ATR

  • Macbook won't start - apple icon turns to circle with diagonal line/slash

    My Macbook won't start. When I turn on the power, the apple icon appears but then after a while it changes to a circle with a diagonal line/slash, then it just shows a gray screen.
    The last time I used the computer I did several software updates. Could this be causing the problem? Any suggestions for getting my computer operating again?
    Thanks for any help/advice.

    Yup, i encountered the same experience after a strange failed USB-loading, and a sudden shutdown of my macbook.
    Luckily i manage to "safe-boot" (pressing "Shift" key once starting up the mac) my macbook so that i can save the necessary files before will lose them all.
    After that i popped-in my SL Installation DVD, and did the reinstallation process. Fortunately, everything works as charm and everything is back to normal after Spotlight has done it's hard work.
    Happy Apple user once again.

  • Looking up the values in a waveform graph with a mouse click

    Hi,
    Does anyone know how to look up the values in a waveform graph with a mouse
    click but... without the cursor legend on, if i press in the waveform graph
    nothing happens, i must search my cursors and only then i can see the values
    of my signal data?! Isn't there any other way?
    Best regards,
    Thijs Boerée

    Dear Chad,
    I know of the function "bring cursor to center". I also figured out that
    when i use a property node of the cursor array of clusters, that i can see
    that some values change when i move the cursor (i can see the X and Y scale
    value change of the graph and also the values of the mouse pointer (in
    points due to screen resolution)) But in this cluster i can't set the mouse
    position. I allready made a VI where i can see the bounds of my
    waveformgraph and I have the Xscale (min and max) and the Yscale (min and
    max), with a linear fit i can translate my mouse position to X an Y scale
    values and when i click on my waveform graph the cursor go's to that
    position (property node of the cursor position), only disadvantage is that i
    only have the bounds of my plot area and not the position, i do have the
    position of my waveform graph but the plot area isn't allways in the center,
    if i could extract the position of the plot area i may find a solution to
    solve this problem.
    And to file a product question:
    I would like to see the function that with a mouse click a little menu
    appears and that there are options to for example set a marker on that data
    and when you right click on it, that there are options to remove it or to
    add comment, a 2D array could make a list of the different channels with
    it's markers (time stamps and comments).
    Best regards,
    And thank you for your help.
    Thijs Boer�e
    "Chad AE" schreef in bericht
    news:[email protected]...
    > Dear Thijs,
    >
    > Thank you for contacting National Instruments.
    >
    > To address your question, there is no direct VI, command, or property
    > node that will allow the cursor snap-to-mouse functionality.
    >
    > I notice a problem you may be occuring is trying to find where the
    > cursor is on the graph. If this is an issue, you can select Bring to
    > Center from the Formatting Ring on the Cursor Legend to move the
    > cursor to the center of the graph.
    >
    > Let me know if you have any further questions or if this does not
    > resolve your issue, as I would be happy to file a product suggestion
    > so that LabVIEW is improved in future versions.
    >
    > Thanks again and have a great day!
    >
    > Chad AE
    > Applications Engineer - National Instruments

  • Maps zoom/scroll with Magic Mouse

    Hi
    In Maps.app, scrolling over the map with magic mouse, moving the map instead of zooming, i need to press SHIFT when i need zoom in or out. Other apps (google maps in safari, or google earth.app) working with zoom set as default. 
    How can i change this behaviour?

    I second this. seems like an oversight. i can live it, i'll just screw up every time I try maps because at this point, google Maps is still better. so it'll be quite some time before i think of Maps first.
    I do feel like Maps is just a Beta right now. There are 0 preferences.
    I tried using Better Touch Tool but it doesn't seem to work... i could be doing something wrong though.
    If someone figures out a trick with the BTT, and Maps, please let us know.
    In the mean time, apple has it's work cut out for it. Maps has Millions of Miles that needs updating/correcting/ect. perhaps in one of it's many to roll outs, they'll give us some preferences.

  • CheckBox Circle with no fill?

    My form has Yes / No option on it and typically users will circle one or the other when they print the blank form.  I know I could change this to a regular check box, radio button, etc.  However, before I do, I thought if you all knew a way to us the form in its current state?  One potential way I though of is to use a checkbox with a very large font size and the circle style.  Works great but the circle has black fill and I need it to be no fill (transparent). I thought I could use a script to change the fill color of the circle, but I'm a total newbie at scripting here and nothing I've come up with is working.
    Any ideas?
    Thank you!

    :-(  Hierarchy is flat on this form.  All shapes, text, circles, etc. are on the same level.
    I have two buttons, ButtonY and ButtonN and one circle at this point.
    The script for ButtonY is:
    ----- topmostSubform.Page1.ButtonY::click: - (JavaScript, client) ----------------------------------
    xfa.form.topmostSubform.Page1.ButtonN.fontColor="255,0,0"
    xfa.form.topmostSubform.Page1.Circle1.presence="invisible"
    For ButtonN:
    ----- topmostSubform.Page1.ButtonN::click: - (JavaScript, client) ----------------------------------
    xfa.form.topmostSubform.Page1.ButtonN.fontColor="0,0,0"
    xfa.form.topmostSubform.Page1.Circle1.presence="visible"
    Both buttons and the circle are on the same level under Page1.
    The fontcolor of ButtonN changes as expected when each button is pressed.  The circle (with a default presence of visible) never becomes invisible when ButtonY is clicked.
    Very frustrating.  Everything seems exactly the same as on the form this works on.  I haven't changed version of Lifecycle or anything.

Maybe you are looking for