[4388] in java-interest

home help back first fref pref prev next nref lref last post

Moving objects in my applets

daemon@ATHENA.MIT.EDU (Laurent Duperval)
Thu Dec 21 15:38:03 1995

From: laurent@Grafnetix.COM (Laurent Duperval)
Date: Thu, 21 Dec 1995 13:19:06 -0500
To: java-interest@java.sun.com

Well, I had originally asked for help in implementing some type of drag and
drop deal but I received no answer.  I came up with this:

class OpaquePanel extends Panel {

	Point clickdown, origLocation, delta;

	public OpaquePanel() {
		super();
	}

	public OpaquePanel(int width, int height) {
		super();
		resize(width, height);
	}

	public boolean mouseDrag(Event e, int x, int y) {

		System.out.println("Mouse drag in OpaquePanel");
		System.out.println("X coord = " + x + ", Y coord = " + y);

		origLocation = location();
		delta = new Point (0,0);
		delta.x = x-clickdown.x;
		delta.y = y-clickdown.y;

		System.out.println("Delta = (" +delta.x + " , " + delta.y + ")");

		move(origLocation.x+delta.x, origLocation.y+delta.y);

		System.out.println("Original Location = (" + origLocation.x + " , " + origLocation.y + ")");

		int addx = origLocation.x+delta.x;
		int addy = origLocation.y+delta.y;

		System.out.println("Redrawing at (" + addx + " , " + addy + ")");

		repaint();

		return true;

	}

	public boolean mouseDown(Event e, int x, int y) {

		System.out.println("Mouse down in OpaquePanel");
		System.out.println("X coord = " + x + ", Y coord = " + y);

		clickdown = new Point(x,y);
		origLocation = location();
		delta = new Point (0,0);
		System.out.println("Original Location = (" + origLocation.x + " , " + origLocation.y + ")");

		return true;
	}

	public boolean mouseUp(Event e, int x, int y) {
		System.out.println("Panel size is: (" + size().width + " , " +
		size().height +")");

		System.out.println("Mouse Up in OpaquePanel");
		System.out.println("X coord = " + x + ", Y coord = " + y);

		return true;
	}
}

class ThruImage extends ImageButton {

	public ThruImage(Image img) {
		super(img,null,null);
	}

	public boolean mouseDrag(Event e, int x, int y) {

		getParent().deliverEvent(e);
		return true;

	}

	public boolean mouseDown(Event e, int x, int y) {

		getParent().deliverEvent(e);
		return true;
	}

	public boolean mouseUp(Event e, int x, int y) {

		getParent().deliverEvent(e);
		return true;
	}
}


The ImageButton class allows one to create a button containing an image.
Check out http://www.cs.brown.edu/people/amd/java/ImageButton/ for more info.
Anyway, this doesn't work like I want.  Movement is jerky and sometimes the
object I'm trying to move doesn't go in the right direction, i.e. it jumps
left when it should go down, etc.

Further more, I've noticed that the Event e coordinate system is not the same
as its parent.  I'm thinking this could explain part of my problem.   When I
move my mouse, the object under it doesn't move as fast.  How can I force my
OpaquePanel to respond to the event according to its coordinate system instead
of its child's coordinate system?

Last, but not least, why is my Panel so small?  The resize command doesn't
seem to work.  Should I subclass a Canvas instead?  Or something else?

Thank you for your help.

-- 
Laurent Duperval, Systems Analyst       Grafnetix Systems Inc.
Tel: (514) 861-3389                     777, de la Commune Ouest
Fax: (514) 866-6206                     Suite 101, Montreal, Qc
Laurent@Grafnetix.COM                   Canada, H3C 1Y1
URL: http://www.grafnetix.COM  
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post