定时器
package day19;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.TimerTask;
import java.util.Timer;
public class World extends JPanel{
public static final int WINTH = 400;
public static final int HEIGHT = 700;
private Sky sky = new Sky();
private Hero hero = new Hero();
private FlyingObject[] enemies = {};
private Bullet[] bullets = {};
void action(){
Timer timer = new Timer();
int intervel = 10;
timer.schedule(new TimerTask(){
public void run(){
System.out.println(111);
}
},intervel,intervel);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
World world = new World();
frame.add(world);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);;
frame.setSize(WINTH,HEIGHT);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
world.action();
}
}