Sie sind auf Seite 1von 3

import java.awt.

Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.Timer;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author kinnaird
*/
public class ball extends JPanel implements ActionListener {
int x,y;
int z,w,t;
int y2;
int x2;
int width;
int height;
int cir1;
int cir2;
int cir3;
int cir4;
boolean up = false;
boolean down = false;
boolean left = false;
boolean right = false;
public ball (){

setPreferredSize(new Dimension(100,100));
x= 10;
y=10;
w=10;
t=345;

cir1=70;
cir2=70;
cir3=50;
cir4=50;

width = 45;
height = 100;
x2= x + width;
y2 = x2 + height;

}
public void moveBall()
{

System.out.println("Iam heererere");
if ((cir1 == x2) || (cir1 == y2))
{
left = true;
System.out.println("left is true");
}

if ((cir1 == x2) || (cir1 == y2))


{
right = true ;

}
while(left == true)
{
cir1 = cir1 +20;
if(cir1 == 345)
{
left = false;

}
}
while (right == true)
{
cir1 = cir1 - 20;
if(cir1 == 120 )
{
right = false;

}
}

public void moveUp()


{

if(y>=1)
{

y= y-10;
repaint();
}
}

public void moveDown()


{

if(y<=400)
{

y = y + 10;

repaint();

}
public void moveUp1()
{
if(w>=1)
{

w = w-10;

repaint();
}
}
public void moveDown1()
{

if(w<=400)
{

w = w+10;

repaint();
}
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
//getHeight();

g.setColor(Color.green);

g.fillRect(x, y, width, height);


g.fillRect(t, w, width, height);
g.setColor(Color.red);
g.fillOval(cir1, cir2, cir3, cir4);

public void actionPerformed(ActionEvent e) {


throw new UnsupportedOperationException("Not supported yet.");
}

Das könnte Ihnen auch gefallen