rendered paste bodypackage shotcaller;import java.awt.*;import java.applet.*;import java.util.*;import javax.swing.*;import java.math.*;import java.awt.event.*;import javax.swing.event.MouseInputAdapter;public class shot extends Applet { public void mouseMoved(MouseEvent e){ x = e.getX(); y = e.getY(); } public class cue { int x; int y; } public class ball { double grav =.6; double damp =.98; int rad = 12; double x; double y; double vx =0; double vy =0; int m = 3; } int i = 0; int j = 0; Object ball; int bmax = 8; ball[] b = new ball [8]; public void fold(){ for (i= 0; i < bmax; i++){ b[i] = new ball(); } b[0].x=70; b[1].x=387; b[2].x=414; b[3].x=444; b[4].x=444; b[5].x=444; b[6].x=414; b[7].x=-100; b[0].y=132; b[1].y=132; b[2].y=117; b[3].y=103; b[4].y=134; b[5].y=165; b[6].y=150; b[0].vx+=40;} public int x = 0; public int y = 0; java.util.Timer timer; Graphics doublebuffer; Image offscreen; private final int WIDTH =550; private final int HEIGHT = 300; public void init(){ fold(); cue c = new cue(); this.setSize(WIDTH,HEIGHT); timer = new java.util.Timer(); timer.schedule(new gameTask(),0,1*5); offscreen = createImage(640,480); doublebuffer = offscreen.getGraphics(); } class gameTask extends TimerTask { public void run(){ repaint(); for (i = 0; i<8; i++){ if(b[i].x>520){ b[i].vx*=-1; } if(b[i].y>270){ b[i].vy*=-1; }if(b[i].y<10){ b[i].vy*=-1; } if(b[i].x<10){ b[i].vx*=-1; } b[i].vx*=b[i].damp; b[i].vy*=b[i].damp; b[i].x +=b[i].vx; b[i].y +=b[i].vy; for (j=1; j<8; j++){ double dx = b[j].x-b[i].x; double dy = b[j].y-b[i].y; double dist = Math.sqrt(dx*dx+dy*dy); if(dist <b[i].rad+b[j].rad){ double angle = Math.atan2(dy,dx); double cosa = Math.cos(angle); double sina = Math.sin(angle); double vx1p = cosa*b[i].vx+sina*b[i].vy; double vy1p = cosa*b[i].vy-sina*b[i].vx; double vx2p = cosa*b[j].vx+sina*b[j].vy; double vy2p = cosa*b[j].vy-sina*b[j].vx; double P = vx1p*b[i].m+vx2p*b[j].m; double V = vx1p-vx2p; vx1p = (P-b[j].m*V)/(b[i].m+b[j].m); vx2p = V+vx1p; b[i].vx = cosa*vx1p-sina*vy1p; b[i].vy = cosa*vy1p+sina*vx1p; b[j].vx =cosa*vx2p-sina*vy2p; b[j].vy = cosa*vy2p+sina*vx2p; double diff =((b[i].rad+b[j].rad)-dist)/2; double cosd=cosa*diff; double sind = sina*diff; b[i].x-=cosd; b[i].y -= sind; b[j].x += cosd; b[j].y += sind; }}} } } public void update (Graphics g) { paint (g); } public void paint(Graphics g) { doublebuffer.clearRect(0,0,550,300); doublebuffer.setColor(Color.black); doublebuffer.fillRect(0,0,550,300); doublebuffer.setColor(Color.green); doublebuffer.fillRoundRect(10,10,530,280,30,30); doublebuffer.setColor(Color.darkGray); doublebuffer.fillOval(0,0,30,30); doublebuffer.fillOval(0,270,30,30); doublebuffer.fillOval(520,0,30,30); doublebuffer.fillOval(520,270,30,30); doublebuffer.fillOval(260,0,30,30); doublebuffer.fillOval(260,270,30,30); for (i=0; i<8; i++){ if(i==0){ doublebuffer.setColor(Color.white); } if(i==1){ doublebuffer.setColor(Color.lightGray); } if(i==2){ doublebuffer.setColor(Color.red); } if(i==3){ doublebuffer.setColor(Color.blue); } if(i==4){ doublebuffer.setColor(Color.orange); } if(i==5){ doublebuffer.setColor(Color.magenta); } if(i==6){ doublebuffer.setColor(Color.yellow); } if(i==7){ doublebuffer.setColor(Color.black); } if(i==8){ doublebuffer.setColor(Color.lightGray); } doublebuffer.fillOval((int)b[i].x,(int)b[i].y,24,24); } doublebuffer.setColor(Color.red); doublebuffer.fillRect(20,20,x,y); g.drawImage(offscreen,0,0,this); }}