java 布林线_java向量组——设计一个球,使它由一边(A点)运动到另一边(B点),运动到中间时,A点出现第二个球...

java向量组——设计一个球,使它由一边(A点)直线运动到另一边(B点),运动到中间时,A点出现第二个球,两球一起运动,当第一个球到达B点时消失(移除),当第二个球运动到中间时,...

java向量组——设计一个球,使它由一边(A点)直线运动到另一边(B点),运动到中间时,A点出现第二个球,两球一起运动,当第一个球到达B点时消失(移除),当第二个球 运动到中间时, A点再出现第一个球和第二个一起运动.........就这样一直重复下去(可在下面改)

public class GoingBoll extends JFrame{

mypanel mp=null;

public static void main(String[] args) {

GoingBoll goingboll=new GoingBoll();

}

public GoingBoll(){

this.setTitle("goingboll");

this.setSize(800,500);

this.setLocation(200, 150);

this.setVisible(true);

mp=new mypanel();

this.add(mp);

}

}

class mypanel extends JPanel implements Runnable{

boll b=null;

public mypanel(){

b=new boll(700, 300, 10);

Thread n=new Thread(b);

n.start();

}

public void paint(Graphics g){

super.paint(g);

g.setColor(Color.blue);

g.fillOval(b.getX(), b.getY(), 50, 50);

this.repaint();

}

@Override

public void run() {

// TODO Auto-generated method stub

try {

Thread.sleep(1000);

} catch (Exception e) {

// TODO: handle exception

}

}

}

class boll implements Runnable{

int x;

int y;

int s;

boolean bLive=true;

//Vectorbolls=new Vector();

public int getX() {

return x;

}

public void setX(int x) {

this.x = x;

}

public int getY() {

return y;

}

public void setY(int y) {

this.y = y;

}

public int getS() {

return s;

}

public void setS(int s) {

this.s = s;

}

public boll(int x,int y,int s){

this.s=s;

this.x=x;

this.y=y;

}

@Override

public void run() {

// TODO Auto-generated method stub

try {

Thread.sleep(2000);

} catch (Exception e) {

// TODO: handle exception

}

while(bLive){

try {

Thread.sleep(7);

} catch (Exception e) {

// TODO: handle exception

}

x-=3;

System.out.println("x="+x);

if(x<50){

bLive=false;

}

}

}

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值