Help, How do i get objects to move with the click of a mouse button?

I am developing a game where by an object can move around the screen by either using the keyboard or the mouse. I have figured out how to control the object using the keyboard. But the mouse control is proving difficult. Can anyone give me some suggestions on how to tackle this?

This is better !:
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
public class MoveO extends Frame implements MouseListener
     Label obj = new Label("@");
public MoveO()
     setBackground(Color.pink);
     addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
          {     dispose();
               System.exit(0);}});
     setLayout(null);
     add(obj);
     obj.setBounds(110,130,20,20);
     obj.setBackground(Color.red);
       setBounds(1,1,600,460);
     setVisible(true);
     addMouseListener(this);
public void mouseEntered(MouseEvent m){}
public void mouseExited(MouseEvent m) {}
public void mouseClicked(MouseEvent m){}
public void mousePressed(MouseEvent m){}
public void mouseReleased(MouseEvent m)
     move2(m.getPoint());
private void move2(Point mto)
     Point ofr = obj.getLocation();
     Line2D.Double line = new Line2D.Double(ofr.x,ofr.y,mto.x,mto.y);
     Rectangle2D.Double r = new Rectangle2D.Double();
     r.setRect(line.getBounds2D());
     if (mto.x >= ofr.x) 
          for (double x=0; x <= r.width; x++)
               for (double y=0; y <= r.height; y++)
                    if (line.ptSegDist(r.x+x,r.y+y) < 0.25)          
                         obj.setLocation((int)(r.x+x),(int)(r.y+y));
     else
          for (double x=r.width; x >= 0; x--)
               for (double y=r.height; y >= 0; y--)
                    if (line.ptSegDist(r.x+x,r.y+y) < 0.25)          
                         obj.setLocation((int)(r.x+x),(int)(r.y+y));                
public static void main (String[] args) 
     new MoveO();
}Noah

Similar Messages

  • My ipad lost it's connection with my printer. How can I get it to reconnect with the printer?

    My iPad lost it's connection with my printer. How do I get it to reconnect?

    1. Reboot iPad
    2. Reboot router

  • When I buy a pre order song how do I get it to play with the rest of the CD?

    When I buy a pre-order song from i tunes, and then purchase the CD the song was from it will not play with the rest of the CD.
    Example: Tori Amos's new CD Unrepentant Geraldines
    I purchased the single Trouble's Lament when it was released, before the CD.
    I just purchased the CD and the song should be #2 on the CD, but its not there, it is listed separately, and will not play with the CD.
    Also, other issue... Free U2 CD, it says its in my Library when I clicked on the CD add in the store. It's nowhere to be found in my library!! I really would love to listen to it since I have several of there CD's and am a big fan
    If anyone can help with either of these issues , I would greatly appreciate it.

    For the single, if you select the track in your library and do 'get-info' (control-I) on it and select its Summary tab on the popup are its details (e.g. album name and artist) the same as for the other tracks on the album ?
    For the U2 album you should be able to download it into your library by ticking the 'show iTunes in the Cloud purchases' tick box on the Store tab in iTunes > Preferences - it should then show in the Music part of your library with a cloud icon against it for downloading (downloading the booklet for it this way may not work, you may get a 'corrupt file' message when trying to open it, though that might have been fixed by now).
    Or go to the Purchased link under Quick Links on the right-hand side of the iTunes store homepage and you should be able to download it from there.
    A third option is to sign out of your account (Store > Sign Out menu option), find the album in the store and then click on its free 'price' button - you should then be prompted to sign back in and the album should download.

  • How can I get Recipefox to work with the latest version (16) of Firefox?

    Recipefox worked on previous versions of Firefox. I could use the Grab It feature on many sites & easily retrieve recipes. Now, with the latest version of Firefox, it does not work on any of the recipe websites. Is there a more recent version of Recipefox that works with Firefox version 16, I am using 0.68. Does Recipefox get updated with newer versions of Firefox.

    Hi,
    You can try to right-click and '''Find Updates''' via '''Tools''' ('''Alt''' + '''T''') > '''Add-ons''' > '''Extensions'''. You can also '''Remove''' it, and search and install via the Search box on the top right or from [https://addons.mozilla.org/en-US/ AMO].
    [https://support.mozilla.org/en-US/kb/Using%20extensions%20with%20Firefox Using Extensions]
    If problems persist you can reset Firefox and start afresh with [https://addons.mozilla.org/en-US/firefox/addon/recipefox/?src=search recipefox].
    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information.
    Note: ''This will cause you to lose any Extensions, Open websites, and some Preferences.''
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!

  • Help, how do I get iPad Photos to sort the way I want?

    I'm at wits end!
    After a week of constant sync/re-sync/re-name-stripping out all EXIF data, I'm still at the mercy of some random sort order for some of my photos.
    I have read: http://support.apple.com/kb/HT4221 - which seems to indicate that it reads the EXIF data first. I have stripped all EXIF data from all my photos in hopes that it will resort to alphabetical order of the file-names. But it doesn't seem to do so - it seems to still rely on last modified date of the file itself. Short of copying individually hundreds of photos over in the order that I want - I don't know what to do. Additionally, through trial and error, it seems that it doesn't recognize differences in timestamp in the seconds, only minutes - ARGH!! Is anyone else having such a hard time to get the iPad to sort the photos by filename in an order that I specify?
    I am not on Mac and cannot use iPhoto to sort, so I am on the PC side and order my photos using ACDSee and batch rename them so that they are alphabetically correct.
    Please, its essential that they are grouped in my order, but I can't for the last week coax my iPad to display in alphabetical filename order (it seems simple enough?!) I'm so frustrated!!
    Please help.

    I do not understand what you mean by a problem with downsizing large image, the images I have dragged over are exactly the same size as on my home computer, I can see it may cause the IPad problems if you are trying to transfer 50 mb tiff files or something similar, it really is not designed for that type of image.
    My workflow is as follows, I work up my raw files and save a copy as a tiff for printed output, for web or iPad use I make an approx 2 Mb jpeg file.
    I make a folder with an appropriate title, insert the required images, the images are sorted either by the original camera file numbering or if I want items in a particular order I will start a number 1 and continue, Airsharing will respect your ordering sequence, so number 1 will always be number 1.
    As a viewer Air Sharing in my opinion is better than the photo app because it leaves your images in the order you have set, to view an image you open the folder click on number 1 or whatever is your 1st image, that
    opens full screen, you have the choice of moving through the folder singly by clicking the arrow head at the bottom right/left of the screen or a slide show by clicking the centre arrow head, you set the time on screen etc.
    If you put the same selection of images on the iPad via the Photo app it would number your images in a way you have little control over and will even optimise your image even if you do not want it to !
    The Airsharing library is seperate from the photo library, you can move images to the photo library but why would you want to do that ? All your image sorting is done on your computer prior to the transfer, surely you do not want an app making decisions on you behalf ?
    To me it is a perfect portfolio app because I make all the decisions about file size, sequence of images how I want to display them, singly or as a slideshow I am in control not Apple.

  • How do I create an object that moves with the mouse?

    I don't use Flash a lot, so things like this confuse me...
    I'm trying to code so that an object, mostly likely a circle, moves
    around when the mouse moves. Also, I want it to disappear when the
    mouse leaves the screen. Can anybody help me do this?
    Thanks.

    circle_mc is the instance name of the circle, so just change
    it to be whatever you want it to be.
    One thing with that, you may want to have the image centered
    within the stage of the movieclip, otherwise it will appear to be
    following the mouse by the corner of it.
    This ain't no carny show, so your shenigans declaration is
    void unless you can get a majority vote and brought your
    broom.

  • Help - How can I get rid of Spyware / Adware [1 click Media]

    I have tried to remove the spyware by unistalling Adobe Flash, by scanning using Intego Virus Barrier but it remains.  The spyware is popping up on my FB page whenever I view a photo.
    I have 2011 Mac Book Pro, running OS 10,9,2
    I am using Firefox
    All software is up to date.
    Thank you
    <Image Edited by Host>

    The Safe Mac » Search Results » adware removal

  • How do you get mod_perl to work with the bundled apache2?

    I have read a few reports on how to get DBD perl working and some people talk about compiling apache 2 and mod_perl, but I want the standard apache2 which is running smoothly with my php install to handle perl too.
    Can someon give me a list of commands and steps to do and run to get this working? I know php, a bit of C have compiled before but allways forget how it is done. I have no problems editing httpd.confs or php.inis so probably perl's configs and configure files won't be a problem. Thanks in advance.

    Thanks for the thought etresoft. I did not find it in the httpd.conf as an so module to be enabled, so I presumed it was nowhere to be found. But it seems it is in the /usr/libexec/apache2 folder just like all the other modules, find found it .
    I just added this to my httpd.conf and now it is working:
    LoadModule perl_module libexec/apache2/mod_perl.so
    Alias /perl/ /Library/WebServer/Documents/perl/
      <Location /perl/>
          SetHandler perl-script
          PerlResponseHandler ModPerl::Registry
          PerlOptions +ParseHeaders
          Options +ExecCGI
          Order allow,deny
          Allow from all
      </Location>
    I was stuck mentally it seems. Thanks for the bump.

  • I want to use Softcard on my Note 4 but I signed up for it with T-mobile first. How do i get to log in with the same account with my Verizon phone?

    I signed up for Softcard while i was with T-mobile but now have left and want to use the same account with my Verizon account but i get some Error message. Cant MNO or something

    It is a bit annoying     when Verizon , ATT and T mobile are all using the same service with Softcard.  But if Google wallet is working for you keep it. 

  • How do I make sidebar div move with the content div in Firefox 14?

    Hello,
    The sidebar div blocks the content div in Firefox 14 when the browser window is resized smaller. In other browsers, this is not a problem.
    The website url is: www.gaddislaw.com
    Thanks for your help!

    I assume you want the main content text to be 'flexible' i.e., narrow and widen when you alter the size of the browser window. If so amend your 'content' css to as below:
    .content {
    padding-top: 25px;
    padding-bottom: 10px;
    margin-left: 290px;
    margin-right: 40px;

  • How do i get firefox to open with the same window size every time, even if the last instance I had open had a different window size because I resized it??

    My firefox opens new windows with a size that equals the current window I have open, or if I have no window open, the last window I closed. I would like to have it open windows the same size every time, regardless of what size the current window is, or what size the last window I closed was. I cannot find a setting or addin to do this anywhere. I have resizer which lets me change the size, but it is annoying that I can't have a default size for windows being opened. I open windows in new windows, not tabs.

    Open link/bookmark in new tab in same window:
    *Middle-click (press the mouse scroll wheel) the link
    *Ctrl+left click the link
    *right-click the link, choose "Open Link in New Tab"
    Open link/bookmark in new window:
    * Shift+Enter on the link
    * Shift+left click on the link
    See: http://www.7is7.com/software/firefox/shortcuts.html

  • How can i make my header move with the page so it always shows

    I reseached the muse guides online but i could not find the answer. Maybe I missed it, butim tired of looking for it.

    maybe try pinning it?

  • In an iPhoto slideshow how do I get it to start with the first image?

    It seems as if the slideshow starts with a ramdom image.
    Is there any way to have an i:Photo slieshow start with the first one in an album?

    When playing a slideshow directly from an album the show will start with the first photo in the album unless another photo is selected.  In that case the slideshow will begin with the selected photo.
    There's also an setting pane for the album slideshow with an option to randomize the photos with each playing.
    Make sure the Shuffle checkbox is not selected.

  • I don't no much, but I can follow instructions. How can I get my rental movie from my iPhone to my iPad.... And I've rentented another movie, now I want to get it from pc to iPad....help be much appreciated...

    I don't know much, but I can follow instructions. How can I get my rental movie from my iPhone to my iPad.... And I've rented another movie, now I want to get it from pc to iPad....help be much appreciated...

    Did you rent the film directly on the iPhone ? I've never rented films, but from : http://support.apple.com/kb/HT1415 :
    You can move the rental between devices as many times as you wish during the rental period. However, the movie can only be played on one device at a time. If you rent a movie on an iPhone, iPad, iPod touch, or Apple TV, it is not transferable to any other device and you must watch it on that device.
    If you've rented a film on your computer's iTunes then you should be able to sync it to your iPad from your computer's iTunes via the Movies tab that shows on the right-hand side of iTunes when you've selected the iPad 'device' on its left-hand side

  • How do I get very short movies to play one after the other?

    How do I get very short movies to play one after the other?
    I have some video tutorials to show me how to use software on the Mac.
    When a short 4 min. video is finished - I have to double click the next one.
    There must be a way to have continuous playing of movies back to back...
    I've looked - I am sure it's obvious...
    Help please.  Thanks!

    make them type 'Music Video', and add info on artist to group them, then play them.

Maybe you are looking for

  • Unable to batch capture-"tape not threaded"

    I've logged some clips and when I go to capture them I get the following message "Unable to proceed-The tape is not threaded." What does that mean? And how can I capture the clips? They were logged via firewire from a Panasonic PVGS150 (mini-dv). I'm

  • I have two Apple ID's on my phone. Help.

    Hello, So apparently I have two Apple ID's on my phone. One for the App store, which is my own, and one of my phone (?) which is my brothers. The deal is, that I've been using my brothers for some time on my old Iphone 4s, but when I got a new iPhone

  • MetaData information about views in a schema--Please help

    I want to access the metadata information about a view say,View1 in the schema schema1.How can this be done?

  • Can someone explain data charges to me?

    Upgraded to a smartphone Samsung Nexus. First Data plan and all. So, what is costing me alot of data when I am at work,home asleep,connected to wifi at home(Xfinity). I am barely on the thing and in three weeks 75% of 1GB is already used. I am not a

  • How to automate the data load process using data load file & task Scheduler

    Hi, I am doing Automated Process to load the data in Hyperion Planning application with the help of data_Load.bat file & Task Scheduler. I have created Data_Load.bat file but rest of the process i am unable complete. So could you help me , how to aut