一个基本问题。# Java - 爪哇娇娃
g*g
1 楼
一个演示我的疑问的简单程序,点击button改变填充Rectangle大小。
假如我想做一个animation让矩形慢慢变大。期间我并不想让其他
控件响应。为什么下面的code不行呢?我知道implements Runnable
就可以,但我想知道为什么一个线程不行?
size++;
repaint();
try {
Thread.sleep(10);
} catch (Exception ex) {
ex.printStackTrace();
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
public class AnimationApplet extends JApplet implements ActionListener {
假如我想做一个animation让矩形慢慢变大。期间我并不想让其他
控件响应。为什么下面的code不行呢?我知道implements Runnable
就可以,但我想知道为什么一个线程不行?
size++;
repaint();
try {
Thread.sleep(10);
} catch (Exception ex) {
ex.printStackTrace();
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
public class AnimationApplet extends JApplet implements ActionListener {