Dragging a Window

Hello,
I am trying to create a window which can be dragged along the screen using the mouse. The source is as follows:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class WindowTest extends Window
implements MouseMotionListener {
   int xDrag = 0;
   int yDrag = 0;
   int x = 0;
   int y = 0;
   int xPos = 0;
   int yPos = 0;
   boolean firstDrag = true;
   public WindowTest(Frame parent) {
      super(parent);
      this.addMouseMotionListener(this);
      this.setSize(200,200);
      this.setBackground(Color.black);
      this.setLocation(200,200);
      this.show();
   public void mouseDragged(MouseEvent e) {
      if( firstDrag) {
         System.out.println("first");
         xDrag = e.getX();
         yDrag = e.getY();
         firstDrag = false;
      else {
         System.out.println("second");
         xPos = (int)(this.getLocation()).getX();
         yPos = (int)(this.getLocation()).getY();
         x = e.getX() - xDrag;
         y = e.getY() - yDrag;
         xDrag = e.getX() - x;
         yDrag = e.getY() - y;
         xPos = xPos + x;
         yPos = yPos + y;
         this.setLocation(xPos,yPos);
         firstDrag = true;
   public void mouseMoved(MouseEvent e){}
   public static void main( String[] args) {
      new WindowTest( new Frame());
}This code works fine when I drag the frame for the first time, however, when I attempt to drag it for a second time the frame positions itself so that the mouse pointer is in the same place as the original drag (try running my code to understand what I mean). How can I correct this bug - any suggestions?
Thank you for your time.

Hmm, I'm not sure why you were checking for the first drag or not, check for a mouse press instead. I used inner classes because I got lazy and didn't want to write out all the methods, but the same thing applies if you want to implement both listeners. Here's the modified code:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class WindowTest extends Window {
   int x = 0;
   int y = 0;
   int xPos = 0;
   int yPos = 0;
   public WindowTest(Frame parent) {
      super(parent);
      this.setSize(200,200);
      this.setBackground(Color.black);
      this.setLocation(200,200);
      this.show();
      addMouseListener(new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
          x = e.getX();
             y = e.getY();
          addMouseMotionListener(new MouseMotionAdapter() {
         public void mouseDragged(MouseEvent e) {
            setLocation(getLocation().x+(e.getX()-x),
            getLocation().y+(e.getY()-y));
   public static void main( String[] args) {
      new WindowTest( new Frame());
}

Similar Messages

  • I can no longer click and drag Safari window to the other desktop.

    I've tried merging all windows and minimizing that single window, then going to the other desktop to open up the window.  That doesn't work--it just opens on the original desktop. 
    When double-clicking on the Safari icon in the dock, the options for desktop appear (none, this desktop, and all desktops).  By clicking on all desktops I am able to go to the other desktop and see my Safari window there, then I can change the option to none again. 
    This is not how it worked before.  I'm supposed to be able to click and drag the window to the other desktop. 
    Any ideas? 
    Update: 
    I pulled one Safari tab out to create a separate window, opened Mission Control, then clicked on the Safari window and dragged it to the small image of the other desktop. 
    The window stayed in the other desktop and now the function of dragging Safari windows to other desktops has returned. 
    Message was edited by: CuriousKathy

    Thanks! I was having the same problem. This resolved it for me.

  • On OSX Lion i used to drag the window to the top of the screen and get maximise, and drag the window right or left to show the both beside each other just like windows 7, How to do it on Mountain lion ?

    On OSX Lion i used to drag the window to the top of the screen and get it maximise, and drag the window right or left to show the both beside each other just like windows 7, How to do it on Mountain lion ?

    That has never been a feature of Mac OS X, but I believe there was some kind of third-party software that could add that capability.  i don't recall what its name is, but you must have had that installed, and it either isn't installed anymore (perhaps removed as incompatible?) or is not working properly in Mountain Lion.

  • Embedded Color Profile is Lost When Content is Published to Web or Dragging Image Window on Desktop

    Hello, Everyone.  I have a question that I have struggled to crack on my own to no avail.  I hope someone here can help.
    I am trying to publish some images to the web using color corrected monitors, RAW format, and a color checker passport to create a perfeect color profile.  Here are the technical details and my workflow.
    Camera: Canon Rebel EOS Xsi
    Format: RAW + L
    Color Space: sRGB
    Color Checker: X-Rite ColorChecker Passport
    Monitor Calibrator: Spyder4 Pro, fully updated software
    Computer: Lenovo T420 ThinkPad
    Second monitor: Samsung LED SyncMaster SA350 (NVIDIA)
    Photoshop: v12.1 x64 (CS5.5)
    Photoshop Color Settings: Custom North America Web/Internet
    RGB: sRGB IEC61966-2.1
    CMYK: U.S. Web Coated (SWOP) v2
    Gray: Gray GAmma 2.2
    Spot: Dot Grain 20%
    Policies
    RGB: Preserve Embedded Profiles
    CMYK: Preserve Embedded Profiles
    Gray: Preserve Embedded Profiles
    After importing the image into Photoshop, I make sure the RAW space is set to sRGB IEC6 1966-2.1
    Use the eyedropper to select a neutral color one step away from pure white on the RAW image of the color checker, create and set the custom white balance.
    set the white balance
    Export the image as a DNG
    Load the DNG into the X-Rite ColorChecker Passport software to create a color profile
    Back to Photoshop
    Open the RAW file
    Set the white balance to the custom profile created above
    Set the color profile created with X-Rite
    Open the color-corrected image in Photoshop (see color setting above)
    Save as JPEG
    Publish
    First, everything seems to go great throughout this entire process, until I see the image on the Web: LINK.  Once published, the image has a very noticible golden-yellow tint to it.  The color-corrected image looks great on both color-calibrated monitors, in RAW and JPEG.  Absolutely perfect.  After noticing the ugly yellow tint in the image I posted to the Web, however, I became aware of a couple more weird things.
    1) When the JPEG was open in Photoshop and I moved the window that contained the image around on my second monitor, the image immediately took on that golden-yellow tint: you can see a screen shot of the color corrected image on my Samsung (bottom) and the yellow version of the same image created when I drag the window around on the Samsung (top) HERE.
    2) When opening the X-Rite software, I got a warning saying that the laptop monitor had been calibrated, but that the Samsung had not.  I got this error even if I calibrated the Samsung monitor right before using X-Rite.  Also, the monitor is definitely calibrated, because the images look great, and the colors match what I see on the laptop.
    3) Recently, I noticed that when waking my computer from sleep, the Samsung monitor no longer holds its Datacolor (Spyder4) calibration.
    I thought the problem I was having might be due to the monitor, for the reasons stated above.  However, I later noticed that when I open the color-corrected JPEG with the default Windows image viewer, it retains the color correction settings.  The image looks fantastic, and doesn't lose it's color profile when I drag the window around.  Also, there seems to be less color loss in the Word documents and PDFs I included this image in: LINK.
    I checked this with several more images, and the results are the exact same.  I scoured the Web as best I could, but my problem seems to be pretty unique.  Does anyone have an idea what might be causing this?
    Thank you!

    Thank you, twenty_one, for taking the time to read my post and put up a reply.  I am going to rebuild my question and post it again here.  But first, to answer some of your points:
    1. A raw file has no color space, until it's opened into one in the raw converter. So this is controlled in ACR, not the camera.
    I just wanted to be as thorough as possible.  One of the steps I took was to set the Color Space setting in my camera to sRGB:
    2. White balance has no bearing whatsoever on camera profiles. A profile is not for white balancing, it's to account for the spectral distribution of the light, which is something else. You make the profile and assign it in ACR, then you white balance for processing. 
    I know.  I wasn't talking about white balance in my camera.  I set the white balance here:
    I grabbed the color for setting the WB here:
    3. If you get a message about monitor calibration upon opening the camera calibration software, something is seriously confused. The two have nothing to do with each other. No relation whatsoever. 
    Camera calibration software?
    4. A corrupted monitor profile will only show up in Photoshop and other color managed software. Other applications that are not color managed will not use the profile and are not affected. So find out which apps are and which aren't before drawing any conclusions.
    Agreed.  That's partly what I am trying to get help with.
    5. Your links don't work, and in any case clicking on links is something most people including myself dislike. It's much better to insert screenshots in the post, by using the camera icon in the reply box.
    I'm new to this forum, so this is helpful to know.  This image shows the color-corrected image (bottom) on my Samsung.  It looks exactly the same in the same window on my laptop monitor.  When I move that window around on my Samsung screen, it turns gold (top).  The image, when posted to the web, looks *similar* to that gold color.
    So let's say I only use Photoshop on my laptop, which is not displaying any colors.  Do you think the golden hue problem will go away?

  • Dragging a window maximises it

    I am running Windows 7 x64.
    Recently, an issue has arisen where any time I drag a window (browser, windows explorer, office etc) the window will maximise.
    THIS IS NOT AERO SNAP!!! This happens when I drag a minimised window into any part of the screen.
    Screenshot: http://i.imgur.com/rtqc0PZ.png
    In the screenshot, you will notice that there are 2 numbers on the screen, green and white. I am fairly sure that the white one is caused by my AMD Catalyst Software, but I have had this installed long before the issue started occurring.
    The green number is new, and I am pretty sure its causing the problem, as it and this issue started happening at the same time.

    A32
    Have you tried removing the CCC and leaving just the driver?  HAve you tried re-installing all the software?
    Wanikiya and Dyami--Team Zigzag

  • Window Tabs: dragging the window tab to the desktop

    Window Tabs: Tried to grab the top of the finder window and wound up dragging the window tab to the desktop.
    This creates a mini-window have to logout to remove.
    If you right click on the finder icon in the dock and select show all windows they are in the list selecting them seems to do nothing but return you to the desktop.
    What the heck is it?

    Hi roninkai I'm also experiencing this behaviour, if you drag a finder window by its tab on to the desktop it creates a mini finder window that doesn't do anything. I keep doing it by mistake.
    You can get rid of them by doing a  Force Quit on the Finder from the Apple menu, this quickly refreshes the desktop and then they disappear.
    Hope they fix this in the next point release.
    Cheers
    Richard

  • Type Tool does not select type by double clicking or click and drag. (Windows CS 5 V15.1)

    Hi,
    My Type Tool does not select type by double clicking or click and drag. (Windows CS 5 V15.1). This is what I have tried so far and the problem still exists.
    Check preferences for "Text": "Select text-object by path only" should be off. Checked. It was off. Didn't fix it.
    Check the toggle for Show/Hide Edges in the View menu. Cmd(Ctrl)-H. Checked. Edges Showing. Didn't fix it.
    Trashed my Prefeerences. Didn't fix it.
    Any other suggestions out there?
    Thank you!!!

    I figured it out! I feel pretty silly, but I will share this in hopes of helping the next person :/ Here goes. Don;t laugh to hard!
    It was the leading! The space between the two lines of text was less than half of the point size of the actual text. So it looked like two lines but there was actually 3.
    Geeze, I'm embarrassed! Thank you for suggesting that I may not need to recreate the entire document, but start with the text, input manually again (even on a new layer, to match the original), which lead to a fix!
    Thank you!!!

  • Screen moves very slow when i drag a window from one corner to other.

    Hi,
    We are taking RDP to windows server 2008 R2 standard using Thin-clients.
    If I drag a window of explorer or browser to other end of screen it is very slow.(it will work as desktop without video drivers).
    Is there any solution for this.
    And By the way what is application getting accelerated mean.
    Thanks in advance...........

    Hi,
    Please check if a normal physical computer has the same issue. If not, I’m afraid that the issue is related to the performance of Thin Clients.
    Please update the firmware and drivers of your thin clients to the latest and try again.
    Thanks.
    Jeremy Wu
    TechNet Community Support

  • Cannot drag firefox window in windows 7 64 bit

    Firefox window refuses to drag around screen using new computer with windows 7 64 bit os. With all other programmes this function works as expected.
    Have been using Firefox on other machines running XP and Vista 32 bit systems and all was well.

    i have the exact same problem, if i have multiple windows open from firefox then i cant switch from them either by clicking on the title bar.... i think the title bar is disabled or something? please mozilla help us figuring this out...

  • If I had mistakenly dragged my Windows Volume into the trash to get rid of it and go back to one OS volume, Is that 100 plus gb available space lost forever?

    I really messed up, I am just wondering if what I have done is okay< I really thought I could remove a Partition by dragging in to trash and automatically my memory would be reallocated to my MacHD volume. Is all hope lost for the 111 GB of disk space I have avaiable? I am running multiple CGI software and my Macbook is now telling me I have run out of available disk space on my HD. even though it says I have 111 GB free. Please help? I would be happy if I can get away with a system's boot. I have back ups.
    Which brings me to my other question, if i use my back up will it return my fresh system's boot to the same way I had it when I backed up last: meaning Partitioned still?
    If you could help me, I would be so greatful.
    El.

    drag to trash just unmounts it.
    hopefully you know and have used your backups and tested that it will restore.
    the way you remove windows is from Boot Camp Assistant, same program you used to partition space.
    With Paragon CampTuneX $20 you can resize space between the two.
    There are erase and restore of a volume or of entire hard drive. Up to you what you want but yes.

  • Alt Option Key PS CC Using Mouse or Tablet drags app window instead of sampling when using Clone too

    When I open PS CC on my Mac Mini (Mavericks Latest version) or my MBPr (same OS.v)
    Here are the steps.
    MacMini and Mac:
    Open Photoshop
    Open any image
    Switch to Pen tool, stamp tool, or any tool that uses Option key as modifer
    Draw a couple points, sample, whatever
    Now, try to modify an anchor point using the convert anchor tool, or sample using the stamp tool. Just hold the option key down and drag.
    WOAH! My entire application is moving around and the modifier isn't working, instead it's modifying the XY of the application window.
    Check this out... When I do this on my girlfriends side of my MBPr, it's fine. Infact I do retouching on her sidebecuase of this. I just noticed it was doing this at work. I don't use PS a lot at work, mostly Illutsrator.
    Anyways...
    Any one else having this problem?
    Devices this is replicated with..
    M$ Mouse on MacMini
    WacomTablet Intuous4 on MBPr
    Just tried using the MBPr track pad, and it's fine.
    I'm starting to think it's the wacom drivers or something.

    I'm not seeing anything there.

  • IDD CS3 Can't drag the window completely open

    This is weird - When working in InDesign (3), Mac osx, oftentimes I cannot drag the lower corner to open up the window. I can make it smaller/narrower but not full screen. I sometimes want to see all the text but also see whatever is on the pasteboard.
    Right now, for example, the window will only allow itself to be dragged 1/2 the width of my screen.
    It's not like this all the time, and I can't find the answer to the problem. It's not a View thing.

    Do you have palettes open on the side? If so collapse them and you should be able to open the window.

  • Cannot Drag Finder Windows

    Hello- I am having a problem with my finder that I have never encountered before.. the windows just will not drag at all. The weird thing is that- whenever I restart the first window that pops up drags fine, but any subsequent finder windows I open after that just will not budge. Sure enough, if I close the one finder window that does drag, I can't get another one to drag again until I restart and get that window back. I have absolutely no idea what is causing this- I have been wracking my brain to come up with a solution and am at a complete loss. Also- every other application window drags perfectly fine on the computer, but for some reason the finder is being really stubborn. I would appreciate any and all help on this matter to hopefully combat this extremely annoying problem.
    Thanks!

    Delete the com.apple.finder.plist file in your /Library/Preferences/ (folder), OPTION-click & hold on the Finder's Dock icon, select Relaunch, and see if that fixes things. If so, reset your Finder preferences. If not, create a new admin user account, log into it, and see if the problem persists. Report back.

  • Dragging tabbed window leaves ghost?

    OK, this is really more of an annoyance, but it's odd, and I'm wondering if anyone else has noticed it.
    When I Cmd-open a window (to make it open in a new window, it goes to a tab. Normally this is fine, but if I'm sorting files from folder to folder, it's easier to have them side by side. But if I drag a tabbed window out, so as to make is a separate window, the drag preview (mini image of the window) gets left on my desktop. It's not clickable or selectable, and if I close all windows, the Finder doesn't recognize it as an open window. Here it is:
    Has anyone else seen this, or know what causes it? I have noticed that Mavericks has some odd issues with desktop images (e.g. the Launchpad icon/dock prefs thing), but this is a new one.

    Are you certain all of TotalFinder was removed? This program by Etresoft can help show what is loading: http://www.etresoft.com/etrecheck
    Here is the thread that implicated TotalFinder. Another person implicated XtraFinder.
    https://discussions.apple.com/message/23490070#23490070
    You can check to see if it is third-party related by running in Safe Mode. If it works in Safe Mode, you have something running that is messing with it.
    http://support.apple.com/kb/HT1564

  • Dragging Document Windows - (Always On Top)?

    PS CS4 - latest
    A few times, I've dragged a document window over(on top of) a set of panels (layers,channels, etc). Once I let go of the mouse, the title bar of that window (the draggable bar) is placed behind the panels (I'm in standard screen mode). Most of the time this isn't an issue, and probably because I've never dragged a small enough document window over a panel set for this to be an issue worth asking about (all times before, the document window was wide enough to extend out behind the panel(s), so I was still able to click on the title bar. So, after moving this small window and letting go of the mouse, the title bar is completely hidden behind the panel. I know I can move the panels around and/or minimize the panels, but I'm wondering if there is a setting where you can have your document windows (always on top) of other panels?

    If you loose a window behind your panels just hit the tab key which hides all tool bars and panels, drag out your window and hit tab key to make your tools/panels visible again. Panels will always be on top of windows.

Maybe you are looking for