import java.awt.Graphics;
import java.util.Random;
public class ThreadClass extends Thread{
public Graphics g;
//用构造器传参的办法将画布传入ThreadClass类中
public ThreadClass(Graphics g){
this.g=g;
}
public void run(){
//获取随机的x,y坐标作为小球的坐标
Random ran=new Random();
int x=ran.nextInt(900);
int y=ran.nextInt(900);
for(int i=0;i<100;i++){
g.fillOval(x+i,y+i,30,30);
try{
Thread.sleep(30);
}catch(Exception ef){
}
}
}
}
public class Main {
//method to print numbers from 1 to 10
public static void printNumbers() {
for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
}
//printing new line
System.out.println();
}
//main code
public static void main(String[] args) {
//thread object creation
Thread one = new Thread(Main::printNumbers);
Thread two = new Thread(Main::printNumbers);
//starting the threads
one.start();
two.start();
}
}