⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 marble.java

📁 200多个自己编的java程序,大家可以学一下.
💻 JAVA
字号:
package marble;
import java.awt.*;
public class Marble extends Thread
{
	
	private int xdir=2*(1-2*(int)Math.round(Math.random()));
	private int ydir=2*(1-2*(int)Math.round(Math.random()));
 
    private boolean running=false;
    private Table table=null;
    protected 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(50);
				
			}
			catch(InterruptedException ie)
			{
				System.err.println("Thread interrupted");
			}
		}
	}
    private void move()
    {
    	x+=xdir;
    	y+=ydir;
    	if((x>table.getSize().width)||(x<0))
    	xdir*=-1;
    	if((y>table.getSize().width)||(y<0))
    	ydir*=-1;
    }
    
    
    


































































































































}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -