Movement of a image...

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class Mouse extends JFrame implements MouseMotionListener {
     JPanel mapPl;
     JLabel label;
     public Mouse()
          Container contentPane = getContentPane();
          mapPl =new JPanel();
          mapPl.setLayout(null);
          label = new JLabel(new ImageIcon( "C://Documents and Settings//Ronald Soh//My Documents//person1.jpg" ));
          //ImageIcon imageIcon = );
          //info.setLocation(50,50);
          label.setBounds(0,0,280,50);
          mapPl.add( label );
          contentPane.add( mapPl );
          contentPane.addMouseMotionListener(this);
contentPane.addMouseListener(new PositionFinder());
contentPane.setBackground(Color.white);
          contentPane.add(mapPl, BorderLayout.CENTER);
          setSize(800,400);
          show();
     public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e)
System.out.println("x = " + e.getX() + ", y = " + e.getY());
private class PositionFinder extends MouseAdapter
public void mousePressed(MouseEvent e)
System.out.println("Point selected: x = " + e.getX() +
", y = " + e.getY());
label.setBounds(e.getX(),e.getY(),280,50);
     public static void main( String args[] )
          Mouse ms = new Mouse();
the program code is as above..
the image will just move to the location where the mouse was clicked..
however..there some diff ..like i point to 200,244..but the image goes to like 178 166 eg..
why is this so..
then how can i apply a sort of gradual movement for the image..
like can see the image slowly moving to the location..my mouse clicked..
or wat i have done is totally wrong..
cos i trying to design a veri simple java..game..
starting by character walking around the map..
but seens diffcult at this point of time..
so should i apply the tiles based??
but i dunno how to use that...
ny assigning tiles to arrays rite..
can anyone pls enlighten me?

public static ArrayList calculatePath(Position p1,Position p2){
ArrayList al=new ArrayList();
ArrayList alReversed=new ArrayList();
float dy=(float)(p1.getY()-p2.getY());
float dx=(float)(p1.getX()-p2.getX());
float m=dy/dx;
float x1=p1.getX();
float x2=p2.getX();
float y1=p1.getY();
float y2=p2.getY();
//System.out.println(m);
if(Math.abs(m)<1){
if(x1<x2){
for(x1=p1.getX();x1<=p2.getX();x1++){
al.add(new Position((int)x1,Math.round(y1)));
y1=y1+m;
}else{
for(x2=p2.getX();x2<=p1.getX();x2++){
alReversed.add(new Position((int)x2,Math.round(y2)));
y2=y2+m;
for(int i=alReversed.size()-1;i>=0;i--){
al.add(alReversed.get(i));
}else{
if(p1.getY()<p2.getY()){
for(y1=p1.getY();y1<=p2.getY();y1++){
al.add(new Position(Math.round(x1),(int)y1));
x1=x1+1/m;
}else{
for(y2=p2.getY();y2<=p1.getY();y2++){
alReversed.add(new Position(Math.round(x2),(int)y2));
x2=x2+1/m;
for(int i=alReversed.size()-1;i>=0;i--){
al.add(alReversed.get(i));
return al;
I just takes two points and generates an ArrayList with all the points in between (the shortest path). It generates only the path from the first point received as argument to the second one.
A Position object has only 2 int fields....
:) **/

Similar Messages

  • How do i move my itunes image to a new PC? Without losing my Data

    How do i move my itunes image to a new PC? Without losing my Data

    These are two possible approaches that will normally work to move an existing library to a new computer.
    Method 1
    Backup the library with this User Tip.
    Deauthorize the old computer if you no longer want to access protected content on it.
    Restore the backup to your new computer using the same tool used to back it up.
    Keep your backup up-to-date in future.
    Method 2
    Connect the two computers to the same network. Share your <User's Music> folder from the old computer and copy the entire iTunes library folder into the <User's Music> folder on the new one. Again, deauthorize the old computer if no longer required.
    Both methods should give the new computer a working clone of the library that was on the old one. As far as iTunes is concerned this is still the "home" library for your devices so you shouldn't have any issues with iTunes wanting to erase and reload.
    I'd recommend method 1 since it establishes an ongoing backup for your library.
    Note if you have failed to move contacts and calendar items across you should create one dummy entry of each in your new profile and iTunes should  merge the existing data from the device.
    If your media folder has been split out from the main iTunes folder you may need to do some preparatory work to make it easier to move. See make a split library portable.
    Should you be in the unfortunate position where you are no longer able to access your original library or a backup then then see Recover your iTunes library from your iPod or iOS device for advice on how to set up your devices with a new library with the maximum preservation of data.
    tt2

  • Can I move all my images to a different folder?

    I started out my project just having the images automatically saved in the same folder as the website (using dreamweaver cs6). Now I'm realizing that I'm probably going to want all those images in an images folder inside my site project because when I move the project to my online server I don't want all the images there in the root.
    Obviously, if I just move the images in windows explorer to a folder the pages I created won't be able to find them. Does DW have a way to move all the images so that it automatically changes the references with it?

    Use DW's Files Panel (F8) to create a new folder.  Right click on site root and select New Folder.
    Then then click and drag  your .jpg and .png files to that new folder.  Assuming your site is properly defined, DW will prompt to update link paths for you.  Click yes.
    Nancy O.

  • How to move the screen (image) when using a tool?

    I know there is a shortcut and I forgot it, I am using the magnetic lasso tool and going through a detailed selection when I need to move the screen image because it is a lot bigger than what I can see. I know there is some keys to press for the hand tool to appear,,,anyone know what they are??
    THanks!!

    Thank you. I knew it was a defect in my head.
    Thanks!

  • Movement of multiple images in Applet

    Hello all
    I am working on this application in which there is a background image and foreground image.now user can move the front image with mouse.intially i was working with single image movement and it worked great.but i changed the code for multiple image movement , its not working. I have used the paint component method of the panel for the drawing. Can any one could give me the idea of doing it in a better way
    Thanx

    I have done it , If any body needs help Please do ask
    thanx

  • How to move ALL my images to a new SSD in laptop

    Howdy,
    I am adding a new SSD to my laptop (ran out of room) and want to move ALL my images (25,000) from my current Drive C to the new Drive D on my Alienware laptop.  How do I do "adjust" LR4 so that it sees the images on the D Drive versus the C Drive?  I can't find an answer and I do NOT want to make a mistake here to say the least
    Thanks,
    Mel

    This explains how to connect to your images on a different drive
    http://www.computer-darkroom.com/lr2_find_folder/find-folder.htm

  • Quicktime movie as an image mask?

    Hello,
    I am trying to use a Quicktime movie as an Image Mask, but it isn't working.  It appears that only the first frame of the movie is being used
    as a still mask, rather than a moving mask.  I have the channel set to Luminance.  Any ideas why movie as Image mask isn't working for me?
    Final Cut Pro 7.0.3
    Thanks,
    meeble

    Hi Meeble,
    What are the specs of the footage and of the sequence. Espessialy the Image Mask. What codec is it etc...
    You are not working with H264 are you? It causes problems like that.
    Rienk

  • Photoshop/Premiere Elements 13...are either capable of making time lapse movies from still images?

    Photoshop/Premiere Elements 13...are either capable of making time lapse movies from still images? I heard this feature was removed from Premiere 13, after I purchased it  =(

    jorgeavanza
    It am not understanding clearly what program is not closing
    Photoshop Elements
    or
    Premiere Elements
    There is the AdobePremiereElements.exe for Premiere Elements (video editing) and the PhotoshopElementsEditor.exe for Photoshop Elements (photo editing).
    Right now you keep mentioning Premiere Elements, but I am seeing your description more like Photoshop Elements.
    Please clarify so that we can focus on the correct program and try to resolve its problems.
    Thank you.
    ATR

  • Can you move a 'Multiple Image Upload' button  into the 'Update Form'?

    I am able to creat and an Update form and an image upload using the "Update Form Wizard" tool and the "Multiple Image Upload" tool succesfully.
    <br />
    <br />The problem comes when I try to move the "UPLOAD" button inside the Update form. Right now it looks like this:
    <br />http://www.webritesolutions.com/Test/upload/now.JPG
    <br />
    <br />This is how I would like it to show:
    <br />http://www.webritesolutions.com/Test/upload/tryingto.JPG
    <br />
    <br />I want to "Upload" button to go next to the "Update record" button. When I do this I get a javascript error and the "Update record" button is disabled.
    <br />Here is the code of what I tried to do:
    <br />
    <br />
    <br />
    <br />
    <br />
    <table>
    <tr class="KT_buttons">
    <td>
    <?php<br />        // Multiple Upload Helper<br /> echo $muploadHelper->Execute();<br /> ?>
    </td>
    <td colspan="1">
    <input type="submit" name="KT_Update1" id="KT_Update1" value="Update record" />
    <br /></td>
    </tr>
    </table>
    <br />
    <br />Here is the Javascript error:
    <br />http://www.webritesolutions.com/Test/upload/error.JPG
    <br />
    <br />thanks for your help.

    A control can only appear once in the visual tree. So you have to remove it from the Grid before you can add it to the DockPanel.
    This code will move the Border element from the Grid to the DockPanel when you click the button:
    Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    Dim border = CType(LayoutRoot.FindName("myborder"), Border)
    LayoutRoot.Children.Remove(border)
    contain.Children.Add(border)
    End Sub
    <StackPanel>
    <Grid x:Name="LayoutRoot">
    <Border x:Name="myborder" BorderBrush="Black" BorderThickness="2">
    <TextBlock>...</TextBlock>
    </Border>
    </Grid>
    <DockPanel x:Name="contain" Background="Yellow">
    <TextBlock>2</TextBlock>
    </DockPanel>
    <Button Click="Button_Click" Content="Move"/>
    </StackPanel>
    You can try it for yourself. But please post your code as formatted text and not as embedded images if you want anyone to be able to reproduce your issue and help you in the future.
    Please remember to close your threads by marking helpful posts as answer.

  • Movie with Rollover Image in Same Place

    My client needs to have the following graphic:
    http://zammedia.com/FreshDesignIncDevelopment/
    With a slideshow movie to the side running continously.. and
    ultimately they would like to have it so that when some rolls-over
    the dots, a specific image pops up in the same window as the movie,
    each pulsating dot bringing up a different image:
    http://zammedia.com/sample2.jpg
    Should this be done in Flash, and if so, how is the best way
    to go about it if I'm really a basic user of Flash.

    So, I've been playing around with your page in dreamweaver and I put a <div> container around your entire web page and then set the width to 1200px. That contained all the contents so that when you re-size the web page the contents don't colapse.
    Not sure if that's what Murray or Nancy mean and am curious if their is a better way.
    That would work although 1200px is too wide.  Something along the lines of 1000px would be better, since you want the page to display in a maximized browser viewport on a 1024 screen without dropping horizontal scrollbars.  I still use 960px as a maximum width....
    Re the centering of the page: Good question I would like to know how to do it "properly"
    In the CSS body rule I put:  margin-left: 20%;
                                                margin-right: 20%;
    Again, I'm not sure if that's the correct way to center the page, and would like to know a better way.
    It's not the best way to do this, which would be to use a fixed width container (as you have done) and just assign it left/right margin settings of 'auto', e.g.,
    #container { width:960px; margin:0 auto; }
    You can center *any* block element within its container with this method.

  • Front Row on Snow Leopard has audio out of sync on movies and TV shows and some movies wont show images.

    I have an iMac Core Duo 2GHz (yes, first Intel iMac). I have Snow Leopard v10.6.8 (latest/last MacOS version I could load) with the most recent Security Update (2013-003).
    I have two issues with Front Row:
    • Some of the movie files will not show the images, but I can hear the audio.
    • On other movies and TV shows they start fine, but within a few minutes the audio is out of sync with the images, running about 3-5 seconds ahead... Looks like a bad dub of a Japanese movie from the 60s.
    Now, I know it's related to Front Row, because when I jump over to iTunes and start the same movie or TV show it begins where I left off in Front Row, but images are fine and audio is suddenly in-sync.
    However, with Snow Leopard being 2 major upgrades back - 3 if you count the upcoming Mavericks release - I doubt this registers as a "brouhaha" on Apple's radar screens. Then, again, maybe the spirit of Steve won't tolerate this Microsoft-like quirk, even if my iMac is still chugging along after 7 years and multiple MacOS X upgrades & updates...

    I think I found my answer... or culprit. It has to do with Snow Leopard, and my iMac Core Duo, being the last of the dying breed of 32-bit systems, and that iTunes v11.x is 64-bit (heavily, at least)...
    Guess I need to break down and replace my 7 year old iMac, even though it still works beautifully (otherwise).

  • In Acrobat XI, how can I select and move multiple text/image blocks simultaneously on the same page?

    I work with student-generated PDFs that require all content to be within a specific margin range. Occasionally tables and figures are indented or otherwise spaced incorrectly so that the content violates the margin requirements. In Acrobat X, I could use the select tool to draw a select box around all of the text and lines within a table, for example, and just slide the entire table over a bit to meet the requirements without sending the PDF back to the author for a correction. This didn't always work, but often enough that I was able to use it on a daily basis.
    Is there a way to select multiple (but not ALL) text blocks and image pieces on a page, so they may be moved simultaneously? If I have to select every text block and line (or every point and line within a graph) and move them each individually, this is going to be a nightmare.
    I have Acrobat XI for both Mac and Windows, but tend to use the Windows version more often.

    Hey, I'm using Acrobat XI and I can't multi select like I use too do with shift as always. Now I get a green note every time I want to multi select with shift + click as always. I also use Pitstop and I get the same green notes.
    Can someone help me ?

  • Vertical scrolling, move and resize image? Is that possible?

    My homepage has a copy of the company logo, large in the center of the page. When I scroll down, I want the logo to move up into the menu and display as a smaller size.
    How can I achieve that?

    Hi Katloubee Yes it is possible in muse. Simply you have to play with opacity in the scrolling effects panel.Mae your first image invisible when you scroll down.
    Firstly you have to place your image and then use the scroll bar effects, make it stuck on the header panel, set its opacity to 0% at initial position and 100% at final. Its not that complicated as I tried to explain it
    If still having trouble, than look for tutorials on adobe tv, regarding scrolling effects & opacity..
    Cheers..!

  • How do you export a movie to an image sequence in iMovie 10.0.4?

    Hi,
    I'm trying to create an animated gif.  In order to do so I need to export my short two-second movie as a sequence of .jpg's or .png's.  This was possible in earlier versions, but I can't find it on this one.
    I'm using an iMac with OS 10.9.4 running iMovie 10.0.4
    If it isn't possible in iMovie 10.0.4, is there another way to create a sequence of images from a short movie using native tools?
    Thank you!
    Clara

    claraefrona wrote:
    Tis a brand new Mac. We didn't update so we don't have the older version.
    I see.
    I know that QuickTime Pro can do it.
    https://www.apple.com/quicktime/extending/
    But that's a $29.99 purchase.
    Not sure about the regular QuickTime Player 7
    QuickTime Player 7 for Mac OS X v10.6.3 or later
    There's also something called Movie2Picture in the Mac App store that I think will do it, but I have no experience with it.
    Lastly, check out MPEG Streamclip it's free and I bet it will export to an image sequence, though I haven't tried it.
    http://www.squared5.com/svideo/mpeg-streamclip-mac.html
    Matt

  • Cannot resize or move a placed image

    I am having issues moving and resizing a image once it has been "placed" onto the document.  It seems to be locked and even when I agree to place the image, I can still not move or resize it.  This happens on all file types and CS6.  Thoughts?

    More information would be needed before anyone can help.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers: 
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

Maybe you are looking for

  • How to run java source files from other java files??

    hello all, i need to run 3 to 4 .java files (first.java,second.java,third.java) from one file. i tried the Runtime.getRuntime().exec(cmd); but here cmd must be an exe file. NOTE THAT i need to run the first.java file ,second.java file each time to ge

  • How to add dynamically a role in a Request Template

    Hi all, We have created a job that reads roles from a custom table and creates them in IDM. We have also a request template of type Assign Roles that has all the allowed roles that can be assigned to a user. We have a requirement to add a role from t

  • Can't turn off metronome on playback

    I recently downloaded the new garageband. I recorded everything with the metronome (and headphones on). Now I would like to play back the song but can;t find a way to turn off the metronome.  Any clues?

  • Window menu is missing in DW CS5 Mac

    I need to open the behaviors panel and I can't get to it. My window menu is missing. I have no idea how long it has been missing - I never open new panels. But, now I need it! Help! Here is a screenshot, it should be bestween Site and Help. How can i

  • PO Mass deletion

    Hi I want to mass delete some 1000 POs in a test environment & reload the same. How to mass delete those POs. Is it possible to delete at header level? or by item level  means how to proceed?