I've been having problems with the now deprecated mouseDown and mouseDrag methods, I know the deprecation causes no problem, the program runs fine, but for grading purposes I want my program to be error and warning free, is there any EASY alternative that can solve this deprecation method? I know the method has been replaced by processMouseEvent but I've had a difficult time understanding the processing and stuff, the only thing I need is to register the position where the mouse was clicked down on the applet, thanks!

Recommended Answers

All 6 Replies

Member Avatar for iamthwee

but for grading purposes I want my program to be error and warning free, is there any EASY alternative that can solve this deprecation method?

Read the updated api for mouse handlers I guess and follow suit.

I HAVE read the information on the official Sun site, but I don't exactly understand what I'm supossed to do, any chance anyone can provide me with an easy example of how the undeprecated (new) method works?

I've been having problems with the now deprecated mouseDown and mouseDrag methods, I know the deprecation causes no problem, the program runs fine, but for grading purposes I want my program to be error and warning free, is there any EASY alternative that can solve this deprecation method? I know the method has been replaced by processMouseEvent but I've had a difficult time understanding the processing and stuff, the only thing I need is to register the position where the mouse was clicked down on the applet, thanks!

Point clicked = null;
public void mousePressed(MouseEvent e)
{
clicked = e.getPoint(); // gives a Point object.
// To get the Point object in (x,y) coordinates
//do (clicked.x, clicked.y)
}

Hope this helps

I've been having problems with the now deprecated mouseDown and mouseDrag methods, I know the deprecation causes no problem, the program runs fine, but for grading purposes I want my program to be error and warning free, is there any EASY alternative that can solve this deprecation method? I know the method has been replaced by processMouseEvent but I've had a difficult time understanding the processing and stuff, the only thing I need is to register the position where the mouse was clicked down on the applet, thanks!

For mouseDown see MouseListener (mousePressed)
For mouseDrag see MouseMotionListener (mouseDragged)

GL

To have a mouseDown procedure, one must implement a MouseListener interface (in java.awt.event).
mouseDrag is similarly implemented via a MouseMotionListener, also in java.awt.event.

However, to have the ability to both detect clicks and movement (quite helpful, really), one must use a different interface.

include javax.swing.event.MouseInputListener (details here)
Note that this is in javax, not java.
Then, define procedures for all the events:
mouseClicked
mouseEntered
mouseExited
mousePressed
mouseReleased
mouseDragged
mouseMoved

The compiler should then not complain about deprecated methods.

Not quite as simple as you wanted, I know. But about as simple as I can find.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.