I need help adding a mouse motion listner to my game. PLEASE i need it for

I need help adding a mouse motion listner to my game. PLEASE i need it for a grade.
i have a basic game that shoots target how can use the motion listner so that paint objects (the aim) move with the mouse.
i am able to shoot targets but it jus clicks to them ive been using this:
public void mouse() {
dotX = mouseX;
dotY = mouseY;
int d = Math.abs(dotX - (targetX + 60/2)) + Math.abs(dotY - (targetY + 60/2));
if(d < 15) {
score++;
s1 = "" + score;
else {
score--;
s1 = "" + score;
and here's my cross hairs used for aiming
//lines
page.setStroke(new BasicStroke(1));
page.setColor(Color.green);
page.drawLine(dotX-10,dotY,dotX+10,dotY);
page.drawLine(dotX,dotY-10,dotX,dotY+10);
//cricle
page.setColor(new Color(0,168,0,100));
page.fillOval(dotX-10,dotY-10,20,20);
please can some1 help me

please can some1 help meNot when you triple post a question:
http://forum.java.sun.com/thread.jspa?threadID=5244281
http://forum.java.sun.com/thread.jspa?threadID=5244277

Similar Messages

  • Plz Help! How to control mouse motion(use program to move/click the mouse)?

    Hi people, plz give me some help on this: I wanna control mouse motion at another program's window, eg. control mouse movement in Internet Explorer's window. For a particular pixel on the screen, I need to move the mouse onto it instantly, then click. Please note that the java program(no applet) is going to run at the background, the current active window is some other programs like IE, notepad, etc.
    Plz give me some clue about how to achieve this, thanks.
    Do I need to do this through windows API or it can be done purely in JAVA?
    Also, how to calculate the RGB color from a particular pixel on the screen?
    Thank you very much for your time, plz help :).

    The same question each day (exe) !!!
    There are many posts on this point!
    All the soft that allows the build a native executable file on Windows
    are not free!
    You can take a look at JET excelsior
    http://www.excelsior-usa.com/home.html
    Denis

  • Need help adding schedule to xcode 4

    I need help adding a tour schedule for an iphone app building an app for 13 djs and they want thier tour schedules added these need to be updated monthly is there a way to add this????

    I don't know if this is the easiest way but it works for me. I connect the DVD player to my camcorder (so it's the 3 plugs yellow/red/white on one end and a single jack into the camera). Then I connect my camcorder to the computer (I think it's through a firewire port). Then I just play the DVD and the footage is digitized via the camcorder and I import it into iMovie 4 as it's playing. I believe the camcorder is just in VCR mode.
    I have also used this method to transfer VHS tapes onto DVDs via the camera by connecting the VCR to the camera.
    I haven't had much luck with movies over about 40 minutes on iMovie. But if it's home movies, there may be a logical break. Do maybe 20 minute segments (it's also really easy on iMovie to add a soundtrack if these are OLD films with no sound.
    As you can see, I'm low tech!
    Good luck!
    Powerbook G4   Mac OS X (10.3.9)  

  • How do add a toolbar to the yahoo firefox? I have a program already downloaded. I need help adding the toolbar.

    I use Roboform and after I downloaded Yahoo Firefox it no longer appeared as one of my toolbars. How do I get it back? I need it for those sites I visit once and a while and filling out forms. I'm using MS 8.1. Thanks.

    If Firefox was able to load and activate the Roboform extension, then you should be able to turn on the toolbar using one of these methods:
    * right-click a blank area of the tab bar, then click on Roboform
    * right-click the "+" button on the tab bar, then click on Roboform
    * "3-bar" menu button > Customize > Show/Hide Toolbars > Roboform
    * (classic menu bar) View menu > Toolbars > Roboform
    If Roboform does not appear on the available toolbar list, could you check to confirm that it is enabled on the Add-ons page? Either:
    * Ctrl+Shift+a
    * "3-bar" menu button (or Tools menu) > Add-ons
    In the left column, click Extensions. In the list on the right, the disabled extensions are at the bottom of the list.

  • Mouse motion listener for JTable with JScrollpane

    Hi All,
    I have added mouse motion listener for JTable which is added in JScrollPane. But if i move the mouse, over the vertical/horizontal scroll bars, mouse motion listener doesn't works.
    So it it required to add mousemotionlistener for JTable, JScrollPane, JScrollBar and etc.
    Thanks in advance.
    Regards,
    Tamizhan

    I am having one popup window which shows address information. This window contains JTable with JScrollPane and JButton components to show the details. While showing this information window, if the mouse cursor is over popupwindow, it should show the window otherwise it should hide the window after 30 seconds.
    To achieve this, i have added mouse listener to JPanel, JTable, JButton and JScrollPane. so if the cursor is in any one of the component, it will not hide the window.
    but for this i need to add listener to all the components in the JPanel. For JScrollPane i have to add horizontal, vertical and all the top corner buttons of Scroll bar.
    Is this the only way to do this?

  • Detect Key Press and Mouse Motion in ONE event?

    Hi
    I am trying to create a functionality where a mouse motion from left to right performs one action, and the same motion while a given key is pressed performs another action.
    How can i combine the two events? How do I unify the KeyEvent and MouseEvent, particulary when I need to capture the directional motion of the mouse together with the key press?
    many thanks for any insight

    you cannot actualy combine them into 1 event but there is an easy way around this:boolean mouseKeyPressed = false;
    public void keyPressed (KeyEvent e)
      if (e.getKeyCode () == ??) \\ or e.isCtrlDown(), e.isAltDown(), ...
        mouseKeyPressed = true;
    public void keyReleased (KeyEvent e)
      if (e.getKeyCode () == ??) \\ or !e.isCtrlDown(), !e.isAltDown(), ...
        mouseKeyPressed = false;
    public void mouseMoved (MouseEvent e)
      if (mouseKeyPressed)
        //processAction
    }hope this helps,
    greetz,
    Stijn

  • Mouse Motion Problem

    I have a JFrame which I have added a MouseMotion Listener to it, it contains many JPanels with border layout manager. I want to detect a MouseMotion in the whole Frame. But I found that only the menu bar area could fire a MouseMotionEvent when the cursor moves there. There are no mouse motion event be fired when the mouse moves on other area on the Frame. What should I do to make it works? Or should I do anything to those insided JPanels ?

    Add your MouseMotionListener to the frame's glass pane. Be sure to set the glass pane visible in order to retrieve the mouse moved events. See attached sample working code.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class GlassMotion
      public static void main(String args[])
        new GlassMotionFrame();
    class GlassMotionFrame extends JFrame implements ActionListener
      JMenuBar mb = new JMenuBar();
      JMenu file = new JMenu("File");
      JMenu edit = new JMenu("Edit");
      JMenu view = new JMenu("View");
      JMenu help = new JMenu("Help");
      JSeparator separator = new JSeparator();
      JMenuItem fileOpen = new JMenuItem("Open...");
      JMenuItem fileSaveAs = new JMenuItem("Save As...");
      JMenuItem editCut = new JMenuItem("Cut");
      JMenuItem editCopy = new JMenuItem("Copy");
      JMenuItem editPaste = new JMenuItem("Paste");
      JMenuItem helpAbout = new JMenuItem("About...");
      JPanel north = new JPanel();
      JPanel south = new JPanel();
      JPanel center = new JPanel();
      JTextField jtf = new JTextField(20);
      JTextArea jta = new JTextArea(20,30);
      JScrollPane jsp = new JScrollPane(jta);
      JButton ok = new JButton("OK");
      GlassMotionFrame()
        super();
        /* Components should be added to the container's content pane */
        Container cp = getContentPane();
        Component glassPane = getGlassPane();
        glassPane.addMouseMotionListener(new MouseMotionAdapter() {
          public void mouseMoved(MouseEvent evt) {
            System.out.println("Mouse motion event!");
        glassPane.setVisible(true);
        north.add(new JLabel("Last Name:"));
        north.add(jtf);
        center.add(jsp);
        south.add(ok);
        cp.add(BorderLayout.NORTH,north);
        cp.add(BorderLayout.CENTER,center);
        cp.add(BorderLayout.SOUTH,south);
        /* Add menu items to menus */
        file.add(fileOpen);
        file.add(separator);
        file.add(fileSaveAs);
        edit.add(editCut);
        edit.add(editCopy);
        edit.add(editPaste);
        help.add(helpAbout);
        /* Add menus to menubar */
        mb.add(file);
        mb.add(edit);
        mb.add(view);
        mb.add(help);
        /* Set menubar */
        setJMenuBar(mb);
        /* Add the action listeners */
        fileOpen.addActionListener(this);
        fileSaveAs.addActionListener(this);
        editCut.addActionListener(this);
        editCopy.addActionListener(this);
        editPaste.addActionListener(this);
        helpAbout.addActionListener(this);
        /* Add the window listener */
        addWindowListener(new WindowAdapter()
          public void windowClosing(WindowEvent evt)
            dispose();
            System.exit(0);
        /* Size the frame */
        pack();
        /* Center the frame */
        Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle frameDim = getBounds();
        setLocation((screenDim.width - frameDim.width) / 2,(screenDim.height - frameDim.height) / 2);
        /* Show the frame */
        setVisible(true);
      public void actionPerformed(ActionEvent evt)
        Object obj = evt.getSource();
        if (obj == fileOpen);
        else if (obj == fileSaveAs);
        else if (obj == editCut);
        else if (obj == editCopy);
        else if (obj == editPaste);
        else if (obj == helpAbout);
    }

  • Regarding restricting mouse motion to a specific JPanel on JFrame

    Hello Everybody,
    I need to restrict mouse motion to a specfic area on a JFrame. I have no idea how to do that.
    Any kind of help will be highly appreciate. I tried to find that on google but could not locate anything that can help me.
    Thanks in advance.

    So, if you were to be able to do that, which you can't, then how would the user close the frame, or use the menu, or click on the task bar, or whatever?

  • Old Motion crashes on start up -- please help

    After not using Motion 1.01 for a while, I need it for a project and it won't start up. I am running OS 10.3.9 on a G4.
    I have tried:
    1) Trashing prefs
    2) Update prebinding (as per http://docs.info.apple.com/article.html?artnum=93984)
    Any help would be much, much appreciated.
    Thanks in advance!
    Crash log:
    Date/Time: 2006-09-06 15:29:44 -0700
    OS Version: 10.3.9 (Build 7W98)
    Report Version: 2
    Command: Motion
    Path: /Applications/Motion.app/Contents/MacOS/Motion
    Version: 1.0.1 (1.0.1)
    PID: 476
    Thread: Unknown
    Link (dyld) error:
    dyld: /Applications/Motion.app/Contents/MacOS/Motion NSLookupSymbolInImage() dynamic library: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ CoreGraphics.framework/Versions/A/CoreGraphics does not define symbol: _CGSSetWindowShadowGroup
    Dual 1 GHz PowerPC G4   Mac OS X (10.3.9)  

    OK. Problem identified and solution posted here for future generations.
    Problem was that I had some bad or missing frameworks.
    I went into /Library/Receipts and deleted relevant receipt files, including:
    - Motion.pkg
    - MotionUpdate1.0.1.pkg
    - PluginManager.pkg
    - ProAppsRuntime.pkg
    - ProAppsUpdate2005-01.pkg
    - ProRuntime.pkg
    Then I re-installed. Problem solved.
    Thanks
    Dual 1 GHz PowerPC G4   Mac OS X (10.3.9)  

  • Reg: MouseListener and Mouse Motion Listener Interfaces

    Hi,
    Good day,
    I have added the mouselistener and mouse motion listeners to JButton..... With this i am trying to draw Circle and Line use mouse... When i was drawing at a particular point the actual drawn one is not placed at that point... so where can be error be present..how to overcome it.........
    Bye

    Insufficient information to find a solution. Please go through these links and respond accordingly.
    [How to ask questions the smart way|http://catb.org/~esr/faqs/smart-questions.html]
    SSCCE
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    db

  • Mouse Motion Listener

    How can i detect when the mose moves when the mouse is not located on the Frame?
    Here is my mouse motion listener
    private class EventHandler implements AWTEventListener {
              private JPanel myPanel;
              public EventHandler(JPanel thepanel){
                   myPanel = thepanel;
            public void eventDispatched(AWTEvent event) {
                if (event.getID() == MouseEvent.MOUSE_MOVED) {
                     MouseEvent me = (MouseEvent)event;
                     myScreenShooter.setCaptureLocation(me.getX(), me.getY());
                    myPanel.repaint();
        }and I register it with a JPanel which I extended
    Toolkit.getDefaultToolkit().addAWTEventListener(new EventHandler(this), AWTEvent.MOUSE_MOTION_EVENT_MASK);But the only time the motion is detected is when the mouse is within the panel...I need to know when it is moved anywhere on the screen.
    Any ideas?
    Thanks

    import java.awt.*;
    import java.awt.event.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    public class MotionTest
        public MotionTest()
            JLabel label = new JLabel();
            label.setHorizontalAlignment(JLabel.CENTER);
            new Monitor(label);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(label);
            f.setSize(300,100);
            f.setLocation(200,200);
            f.setVisible(true);
        public static void main(String[] args)
            new MotionTest();
    class Monitor
        JLabel label;
        Point lastLocation;
        boolean continueToMonitor;
        NumberFormat nf;
        public Monitor(JLabel label)
            this.label = label;
            lastLocation = new Point();
            continueToMonitor = true;
            nf = NumberFormat.getInstance();
            nf.setMaximumFractionDigits(1);
            new Thread(runner).start();
        Runnable runner = new Runnable()
            public void run()
                while(continueToMonitor)
                    Point p = MouseInfo.getPointerInfo().getLocation();
                    double distance = p.distance(lastLocation);
                    if(distance != 0)
                        Toolkit.getDefaultToolkit().beep();
                        label.setText("mouse moved " + nf.format(distance));
                        lastLocation = p;
                    else
                        label.setText("mouse still");
                    try
                        Thread.sleep(250);
                    catch(InterruptedException ie)
                        System.err.println("interrupt: " + ie.getMessage());
    }

  • Constraining mouse motion to specific distance (width and height)

    Hi,
    I want to constrain the mouse motion over a canvas by allowing it to move through specified distance (width and height).
    How can i do this?
    What does the translatePoint() in MouseEvent do? How do i use it?
    Can someone help me with this?
    Thanks
    Niteen

    The correct way with Pixel Bender 1.0 is indeed to pass in the width and height as parameters. There are no ramifications.

  • I am locked out of my iPad, I can't back it up because it won't connect to iTunes (because it's locked with a password) and I need it for school, it has all of my school work on it and the school doesn't have or passwords. PLEASE HELP ME!!!

    I am locked out of my iPad 2, I can't back it up because it won't connect to iTunes (because it's locked with a password) and I need it for school, it has all of my school work on it and the school doesn't have or passwords. I can't loose all of my work. PLEASE HELP ME!!!

    Hi ebby,
    Here are the instructions for a disabled device - hopefully you have sync'd with your computer before now?
    http://support.apple.com/kb/HT1212
    Good luck!
    Cheers,
    GB

  • I just purchased Time Capsule today.  I ONLY want to use it as an external drive.  I do not need it for Time Machine. I can see the TC in my finder, but when I click on a file or video to drag and drop, I get message that TC can't be modified. Help please

    I just purchased Time Capsule today.  I ONLY want to use it as an external drive.  I do not need it for Time Machine. I need to free up room on my computer. As of now, I can't even load updates. I can see the TC in my finder, but when I click on a file or video to drag and drop, I get message that TC can't be modified. Help please!

    I agree with Kappy.. passing files and especially via wireless is slow as slow.
    Just need to be sure your TC is the new AC model??
    And the OS on the computer is Lion?
    Have you completed the setup of the TC via the utility? You do still need to get internet via the TC so it has to be plugged into the main router..
    Give us the full picture of the network.
    Then we can help you get into it.. whether you should put your files on it is another question.

  • Need driver for canon mg 5250 as scanner is not working with version 10.7. Can you please help me to find the driver so scanner works with WIFI?

    need driver for canon mg 5250 as scanner is not working with version 10.7. Lion. Can you please help me to find the driver so scanner works with WIFI?

    Try with the latest Apple driver package for Canon (released 15th Feb):
    http://support.apple.com/kb/DL899
    This solved my problem with the printing.

Maybe you are looking for