M
Mark
I am trying to make an applet so that when my mouse enters the applet
box, the text will hover around it until it leaves the applet box. I
have tried using loops to attain this but I have had no luck. Can
someone please explain how I can do this?
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class ClickName extends Applet implements MouseListener
{
//variable named "square" with data type from Square.class
private Square square = null;
private static final int WIDH = 7;
public void init()
{
addMouseListener(this);
}
public void paint(Graphics g)
{
//draw a black border and a white background
g.setColor(Color.black);
g.fillRect(0, 0, getSize().width - 1, getSize().height - 1);
g.setColor(Color.black);
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
//draw the spot
g.setColor(Color.orange);
if (square != null)
{
//draw a rectangle and send to graphics program
g.drawString("Mark Waddoups", square.x - WIDH, square.y - WIDH);
}
}
public void mouseEntered(MouseEvent event)
{
int x = 1;
if (square == null)
{
square = new Square(WIDH);
}
square.x = event.getX();
square.y = event.getY();
repaint();
}
public void mousePressed(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseClicked(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}
box, the text will hover around it until it leaves the applet box. I
have tried using loops to attain this but I have had no luck. Can
someone please explain how I can do this?
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class ClickName extends Applet implements MouseListener
{
//variable named "square" with data type from Square.class
private Square square = null;
private static final int WIDH = 7;
public void init()
{
addMouseListener(this);
}
public void paint(Graphics g)
{
//draw a black border and a white background
g.setColor(Color.black);
g.fillRect(0, 0, getSize().width - 1, getSize().height - 1);
g.setColor(Color.black);
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
//draw the spot
g.setColor(Color.orange);
if (square != null)
{
//draw a rectangle and send to graphics program
g.drawString("Mark Waddoups", square.x - WIDH, square.y - WIDH);
}
}
public void mouseEntered(MouseEvent event)
{
int x = 1;
if (square == null)
{
square = new Square(WIDH);
}
square.x = event.getX();
square.y = event.getY();
repaint();
}
public void mousePressed(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseClicked(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}