Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class RollThemOut extends Applet implements MouseListener, MouseMotionListener
{
private Point blkball1, blkball2, blkball3, blkball4,whtball1, whtball2, whtball3, whtball4, mouse;
private int select;
public void init()
{
this.addMouseMotionListener(this);
this.addMouseListener(this);
select=0;
blkball1 = new Point(15,110);
blkball2 = new Point(60,110);
blkball3 = new Point(105,110);
blkball4 = new Point(150,110);
whtball1 = new Point(195,106);
whtball2 = new Point(250,106);
whtball3 = new Point(305,106);
whtball4 = new Point(360,106);
mouse = new Point();
}
public void paint(Graphics g)
{
drawBox(g);
g.setColor(Color.black);
g.fillOval(blkball1.x, blkball1.y, 45, 45);
g.fillOval(blkball2.x, blkball2.y, 45, 45);
g.fillOval(blkball3.x, blkball3.y, 45, 45);
g.fillOval(blkball4.x, blkball4.y, 45, 45);
g.drawOval(whtball1.x, whtball1.y, 55, 55);
g.drawOval(whtball2.x, whtball2.y, 55, 55);
g.drawOval(whtball3.x, whtball3.y, 55, 55);
g.drawOval(whtball4.x, whtball4.y, 55, 55);
}
public void mouseDragged(MouseEvent e)
{
if (select==1) blkball1 = mouse;
if (select==2) blkball2 = mouse;
if (select==3) blkball3 = mouse;
if (select==4) blkball4 = mouse;
if (select==5) whtball1 = mouse;
if (select==6) whtball2 = mouse;
if (select==7) whtball3 = mouse;
if (select==8) whtball4 = mouse;
repaint();
}
public void mouseMoved(MouseEvent e){}
public void mousePressed(MouseEvent e)
{
mouse = e.getPoint();
if (mouse.x > blkball1.x - 10 && mouse.x < blkball1.x + 10 &&
mouse.y > blkball1.y - 10 && mouse.y < blkball1.y + 10) select = 1;
if (mouse.x > blkball2.x - 10 && mouse.x < blkball2.x + 10 &&
mouse.y > blkball2.y - 10 && mouse.y < blkball2.y + 10) select = 2;
if (mouse.x > blkball3.x - 10 && mouse.x < blkball3.x + 10 &&
mouse.y > blkball3.y - 10 && mouse.y < blkball3.y + 10) select = 3;
if (mouse.x > blkball4.x - 10 && mouse.x < blkball4.x + 10 &&
mouse.y > blkball4.y - 10 && mouse.y < blkball4.y + 10) select = 4;
if (mouse.x > whtball1.x - 10 && mouse.x < whtball1.x + 10 &&
mouse.y > whtball1.y - 10 && mouse.y < whtball1.y + 10) select = 5;
if (mouse.x > whtball2.x - 10 && mouse.x < whtball2.x + 10 &&
mouse.y > whtball2.y - 10 && mouse.y < whtball2.y + 10) select = 6;
if (mouse.x > whtball3.x - 10 && mouse.x < whtball3.x + 10 &&
mouse.y > whtball3.y - 10 && mouse.y < whtball3.y + 10) select = 7;
if (mouse.x > whtball4.x - 10 && mouse.x < whtball4.x + 10 &&
mouse.y > whtball4.y - 10 && mouse.y < whtball4.y + 10) select = 8;
}
public void mouseClicked(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void drawBox(Graphics g)
{
g.setColor(Color.black);
g.fillRect(10,100,685 ,68);
g.fillOval(410, 55, 65, 65);
g.fillRect(410, 85, 65, 25);
g.fillRect(690, 107, 20, 55);
g.setColor(Color.white);
g.fillRect(15,105,675,58);
g.fillOval(415, 60, 55, 55);
g.fillRect(415, 90, 55, 20);
g.fillRect(690, 112, 30, 45);
}
}
Bookmarks