📄 marble.java
字号:
import java.awt.*;
public class Marble extends Thread
{
private int xdir=5*(1-2*(int)Math.round(Math.random()));
private int ydir=5*(1-2*(int)Math.round(Math.random()));
private boolean running=false;
private Table table=null;
public static int x,y;
public Marble(Table _table,int _x,int _y)
{table=_table;
x=_x;
y=_y;
start();
}
public void start()
{running=true;
super.start();
}
public void halt()
{running=false;}
public void run()
{while (running)
{move();
try
{sleep(100);}
catch(InterruptedException ie)
{System.err.println("Thread interrupted");}
table.repaint();
}
}
private void move()
{x+=xdir;
y+=ydir;
if((x>table.getSize().width)||(x<0))
xdir*=(-1);
if((y>table.getSize().height)||(y<0))
ydir*=(-1);
}
//public void draw(Graphics g)
//{g.setColor(Color.black);
//g.fillOval(x,y,20,20);}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -