import java.awt.
* ;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
class graphics2 extends Frame implements Runnable
{ Thread t;
int a=500,b=290,h=50,w=50;
static int s=0,z=0;
static int p=385,q=326,r=10,m=10;
int l[]={310,330,350,330};
int k[]={320,330,320,390};
static int x,y;
int xDx=10,yDy=10;
double angle=Math.PI/180*10;
private boolean xUp, yUp, bouncing=true;
boolean launchBall=false;
float cpx,bpx,cpy,bpy;
double dist;
public graphics2()
setTitle("my frame");
setSize(900,900);
setVisible(true);
t=new Thread(this,"name");
t.start();
addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent arg0){
int code = arg0.getKeyCode();
switch(code)
case KeyEvent.VK_RIGHT : for(int i=0;i<=3;i++)
k[i]=k[i]+10;
System.out.println("right
"+k[i]+" "+l[i]);
break;
case KeyEvent.VK_LEFT : for(int i=0;i<=3;i++)
k[i]=k[i]-10;
System.out.println("left "+k[i]+"
"+l[i]);
}
break;
case KeyEvent.VK_UP : for(int i=0;i<=3;i++)
l[i]=l[i]+10;
System.out.println("up "+k[i]+" "+l[i]);
break;
case KeyEvent.VK_DOWN : for(int i=0;i<=3;i++)
l[i]=l[i]+10;
System.out.println("down "+k[i]+" "+l[i]);
case KeyEvent.VK_SPACE: launchBall=true;
break;
case KeyEvent.VK_R: repaint();
break;
}
public void keyReleased(KeyEvent arg0)
repaint();
public void keyTyped(KeyEvent arg0)
repaint();
});
public void paint(Graphics g)
int x=500,y=500;
Graphics2D g1 = (Graphics2D)g.create();
int k1[]={};
int k2[]={};
g.drawOval(100,100,x,y);
g.drawOval(90,95,515,515);
g.setColor(Color.RED);
g.drawPolygon(k,l,4);
g.fillPolygon(k,l,4);
int p1[]={210,250,230,250};
int q1[]={220,250,280,270};
if(launchBall==true)
bpx=p;
bpy=q;
System.out.println("bpx="+bpx);
cpx=a+(h/2);
cpy=b+(w/2);
System.out.println(h+" "+w+" "+r);
//System.out.println(cpx+" "+cpy);
//NOT NECESSARY DIST IS ALWAYS "1"
//dist=(Math.pow((Math.pow((cpx-bpx),2)+Math.pow((cpy-
bpy),2)),(1/2)));
//dist=1;
if((r==0) && (m==0))
p=385;
q=326;
m=10;
r=10;
g.drawOval(p,q,r,m);
if((p>=591))
launchBall=false;
r=0;
m=0;
g.drawOval(p,q,r,m);
else
p=p+5;
g.drawOval(p,q,r,m);
g.setColor(Color.GREEN);
g.fillOval(p,q,r,m);
}
System.out.println(a+" "+b+" "+r);
cpx=a+(h/2);
cpy=b+(w/2);
//System.out.println(cpx+""+cpy);
//NOT NECESSARY DIST IS ALWAYS "1"
//dist=(Math.pow((Math.pow((cpx-bpx),2)+Math.pow((cpy-
bpy),2)),(1/2)));
//dist=1;
g.drawOval(a,b,h,w);
g.setColor(Color.BLUE);
g.fillOval(a,b,h,w);
if ( xUp == true )
a += xDx;
else
a -= xDx;
if ( yUp == true )
b += yDy;
else
b -= yDy;
if ( b <= 140 )
yUp = true;
yDy = ( int ) ( Math.random()* 10 + 2 );
else if ( b >= 500 )
yDy = ( int ) ( Math.random() * 10 + 2 );
yUp = false;
if ( a <= 150 )
xUp = true;
xDx = ( int ) ( Math.random() * 10 + 2 );
}
else if ( a >= 550 )
xUp = false;
xDx = ( int ) ( Math.random() * 10 + 2 );
public void run()
try
while(true)
Thread.sleep(50);
s++;
repaint();
catch(Exception e)
{}
public static void main(String args[])
new graphics2();