package frame;
import java.awt.Graphics;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
private Angle angolo;
private int velocita;
public void start(){
this.start.start();
}
public void stop(){
this.start.stop();
}
public Palla(){
this(new Angle(), 5);
}
public Palla(Angle pAngolo){
this(pAngolo, 5);
}
public Palla(Angle pAngolo, int pVelocità ){
super();
super.setBounds(185, 185, 30, 30);
this.angolo= pAngolo;
this.velocita=pVelocità ;
}
@Override
protected void paintComponent
(Graphics g
) {
g.fillOval(0, 0, 30, 30);
super.paintComponent(g);
}
public void run() {
int x=0;
int y=0;
while(true){
x=(int) (this.angolo.getX()*this.velocita);
y=(int) (this.angolo.getY()*this.velocita);
this.setLocation(this.getLocation().x+x, this.getLocation().y-y);
if(this.getLocation().x<=0 || this.getLocation().x>=370){
this.angolo.setAngolo(180-this.angolo.getAlfa());
while(this.getLocation().x<=0 || this.getLocation().x>=370){
x=(int) (this.angolo.getX()*this.velocita);
y=(int) (this.angolo.getY()*this.velocita);
this.setLocation(this.getLocation().x+x, this.getLocation().y-y);
}
}
if(this.getLocation().y<=0 || this.getLocation().y>=340){
this.angolo.setAngolo(-this.angolo.getAlfa());
while(this.getLocation().y<=0 || this.getLocation().y>=340){
x=(int) (this.angolo.getX()*this.velocita);
y=(int) (this.angolo.getY()*this.velocita);
this.setLocation(this.getLocation().x+x, this.getLocation().y-y);
}
}
try {
}
}
}
}