利用多线程编程实现一个正在旋转的地球
程序代码:
package TestSY; import java.awt.*; import import import java.applet.*; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.swing.JPanel; public class TestRunnable extends Applet implements Runnable{ Thread Thread; public Image image = null; public int t = 0; public void start(){ Thread = new Thread(this); Thread.start(); } public void run(){ while(true){ this.setSize(1000, 600); repaint(); try{ Thread.sleep(100); }catch(InterruptedException e){ e.printStackTrace(); } } } public void paint(Graphics g){ try { image = ImageIO.read(new File("E:/zp/" + t + ".png")); t = (t + 1) % 110 ; g.drawImage(image, 0, 0, getWidth(), getHeight(), null); } catch (IOException e) { e.printStackTrace(); } } }