boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 倒霉的Swing代码总是导致Exception, fatal error
相关主题
ZT: 关于性爱的多线程问题研究(一)
can applet implements runnable?
输入中文导致的死 机
eclipse 怪问题
ThreadLocal 的一个 use case
Re: How to showStatus in Applet?
Re: connection pool
问个Thread 的问题,java certificate里的
●●●●紧急求助JAVA初级问题,今天project due●●●●
能这么 create thread 吗?
相关话题的讨论汇总
话题: textpane话题: tpappender话题: public话题: new
进入Java版参与讨论
1 (共1页)
b***i
发帖数: 3043
1
下面main代码如果comment,则程序正常。否则每10次有大概一次出问题。咋回事?
theFrame=new JFrame();
theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
theFrame.setLayout(new BorderLayout()); // original border layout
textpane = new JTextArea(20,40);
textpane.setSize(300,300);
textpane.setText("Please wait for the main to load");
JScrollPane js=new JScrollPane(textpane);
theFrame.add(js, BorderLayout.PAGE_START);
theFrame.pack();
theFrame.setVisible(true);
其他地方,只有这里需要theFrame
if (condition never true when running){
theFrame.setVisible(true);
theFrame.toFront();
}
还有一个需要textpane的地方,在一个函数里,已经把直接调用swing改成invokeLater了
class TPAppender extends SwingInvoker{
String content;
TPAppender(String x){content=x;}
@Override
public void run() {
textpane.append(content);
}
}
System.out.println(x);
if (level if (textpane!=null){// the following line is causing java 6 to crash
(new TPAppender(x+"\n")).execute();//textpane.append(x+"\n");
}
}
下面是SwingInvoker
public abstract class SwingInvoker implements Runnable {
public void execute(){
if (SwingUtilities.isEventDispatchThread())
run();
else
SwingUtilities.invokeLater(this);
}
public void executeNow(){
if (SwingUtilities.isEventDispatchThread())
run();
else
try {
SwingUtilities.invokeAndWait(this);
} catch (Exception e) {
System.out.println("Error from invoker");
e.printStackTrace();
}
}
}
b*******n
发帖数: 449
2
一个简简单单的SwingUtilities.invokeLater()就干完的事情,你搞那么复杂干啥?
1 (共1页)
进入Java版参与讨论
相关主题
能这么 create thread 吗?
implements runable 和 extends thread
几个问题
一个基本问题。
关于inner class的继承
线程问题。
再问一个今天的面试题
Question: reflection and generics
新手问一个多线程的问题
想听本版对下面这段话的点评
相关话题的讨论汇总
话题: textpane话题: tpappender话题: public话题: new