I started out by creating an applet with the size of 400x400 pixels. Draw three horizontal lines and three vertical lines that evenly divide the area into 16 cells. Based on mouse movement over the boxes, a box has been created in cell one, (this was just a guessing place to start for me), as the mouse is moved over each of the sixteen squares the white box created should move to the box the mouse is pointing in (and disappear from the previous box the mouse was in.)
I am now stuck and don't know where to go next. I have read all of the mouse event and etc. but just don't get the next move. Any advice would be appreciated.
Here is my code.
import java.awt.*; import java.awt.event.*; import java.applet.Applet; /* <applet code="Assign10" width=400 height=400> </applet> */ public class Assign10 extends Applet implements MouseListener, MouseMotionListener { public void init() { addMouseListener(this); addMouseMotionListener(this); } public void paint(Graphics g) { g.setColor(Color.blue); setBackground(Color.blue); //draw vertical lines for (int x=100; x<=300; x+=100) { g.setColor(Color.red); g.drawLine (x,0, x,400); } //draw horizontal lines for (int y=100; y<=300; y+=100) { g.setColor(Color.red); g.drawLine (0,y, 400,y); } //draw square g.setColor(Color.white); g.drawRect(10, 10, 80, 80); setSize(400,400); } //Handle mouse moved. public void mouseMoved(MouseEvent me) { } //Handle mouse entered. public void mouseEntered(MouseEvent me) { } //Handle mouse exited. public void mouseExited(MouseEvent me){ } //Handle mouse click. public void mouseClicked(MouseEvent me) { } //Handle button pressed. public void mousePressed(MouseEvent me) { } //Handle button released. public void mouseReleased(MouseEvent me) { } //Handle mouse dragged. public void mouseDragged(MouseEvent me) { } }