日期:2014-05-20  浏览次数:20805 次

急急急~紧急求助一个问题!
想实现这样一个功能:在弹出的窗口中,每隔一段时间,用画笔graphics.drawString()写入一行信息,我在paint()方法里这样写:
public void paint(Graphics g){

int count = 0;
String str = "";
while(count < 100){
str = result.get(count);    //这一行错误
g.drawString(str, infoX, infoY);
count++;
infoY += 5;
}
}
错误如下:
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at MyFrame.paint(MerryMatch.java:195)
麻烦各位,帮忙解答一下这个问题的算法或者思路~

------解决方案--------------------


还有个问题就是因为主程序的循环一直在改变这俩变量的值

主线程的执行时间相比于线程重画的时间 是很短的 也许还没来得及重画 就Over了

还有这些可能性 是不是线程的run方法写错了? 或者你的线程根本就没start启动?