Loan | How to Camp Out | The eBay Song | Zietuwel.nl | Myspace Happy Birthday Comments
Need help with Java Assignment [Archive] - PCMech Forums

PDA

View Full Version : Need help with Java Assignment


Zerostatic
09-20-2003, 03:25 PM
Guys, I started my first Java course a couple of weeks ago and I'm having some problems with my current assignment. If anybody out there can spare a few minutes to help me out it will be greatly appreciated. Thanks

We are using a graphics package called OOPS. We are supposed to make a class for a very simple cartoon character and output 3 instances of the same character on the screen at once.

I got that done ok

But now we have to use mouse events to be able to do the following:
1) Be able to drag the cartoon as whole
2) However there should be one part of the cartoon that can be dragged independent of the rest. That is, if you drag that component, it moves without the rest of the cartoon moving. If later the whole cartoon is moved, that part should maintain its relative placement to the rest of the Kritter.

The following is my code (the cartoon clas is below Myapp):

import OOPS.SP.*;
public class Myapp extends Frame{
private Snowman _snowmanA, _snowmanB, _snowmanC;

public Myapp(){
_snowmanA = new Snowman ();
_snowmanB = new Snowman ();
_snowmanC = new Snowman ();
_snowmanA.setLocation (50, 240);
_snowmanB.setLocation (300, 240);
_snowmanC.setLocation (550, 240);
}

public static void main (String[] argv) {
new Myapp();
}
}



import java.awt.event.*;
import OOPS.SP.*;
public class Snowman
{
private Ellipse _head, _body, _leftEye, _rightEye, _lowerbody;
public Snowman ()

{
_lowerbody = new Ellipse (java.awt.Color.blue);
_body = new Ellipse (java.awt.Color.blue);
_body.setSize (100,100);
_lowerbody.setSize (120,120);
_head = new Ellipse (java.awt.Color.blue);
_head.setSize (80, 80);
_leftEye = new Ellipse (java.awt.Color.orange);
_leftEye.setSize (15, 15);
_rightEye = new Ellipse (java.awt.Color.orange);
_rightEye.setSize (15, 15);
}

public void setLocation (int x, int y){
_lowerbody.setLocation (x-10,y + 120);
_body.setLocation (x, y+60);
_head.setLocation (x+10, y);
_leftEye.setLocation (x+25,y+25);
_rightEye.setLocation (x+65, y+25);
}

public void mouseDragged(MouseEvent abc){
int x = abc.getX();
int y = abc.getY();
setLocation(x, y);
}
}