我做了一个SWING的程序,大概意思是要处理一个数据结构,在处理的过程中把相应的处理信息写到SWING的JTextArea里。
由于我以前没有做过SWING的程序,因此也没有使用什么多线程,就硬着头皮写了个单线程的。程序的大概意思如下:
/*这个是GUI类,也是程序的main入口类*/
class QuestionGUI extends JFrame{
private JTextArea textArea = null;
private JButton button = null;
...... public QuestionGUI(){
//组件初始化
init();
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//当事件触发时进行处理
doProceed();
}
}
} public void init(){
//初始化TextArea和Button
textArea = new JTextArea("",6,19);
button = new JButton("ok");
......
}
//自己实现的为textarea写入内容的打印函数
public void println(String str){
this.textArea.setText(str);
}
//处理函数,处理的具体逻辑封装在另外一个类里。
public void doProceed(){
QuestionProceed qp = new QuestionProceed(this);
qp.doSometing();
} public static void main(String[] args){
//主函数,这里我没有使用多线程
QuestionGUI qig = new QuestionGUI ();
qig.setVisiable(true);
}
}/*这是具体实现处理逻辑的类*/
class QuestionProceed{
//保存一个gui对象,用以调用println方法写textarea
private QuestionGUI gui = null; //构造函数接受gui类传来的对象
public Question(QuestionGUI gui){
this.gui = gui;
}
//具体的处理逻辑,在这里就简化为直接打印一个值
public void doSometing(){
this.gui.println("I am here!");
}
}执行这个程序的预期效果是,产生一个包含TextArea和Button的窗体,一按Button,窗体的TextAera中出现"I am here!"的字样。可是我在实现了相应的程序后,发现在IDE中调试没有问题,可是一旦打成jar包在系统中独立执行的时候,TextArea中的字就出不来。这是为什么呢?是线程的原因还是程序的结构不对?一般来说,如果要形成我想要的功能逻辑,SWING程序应该如何布局比较合理呢?望高手们指点。
由于我以前没有做过SWING的程序,因此也没有使用什么多线程,就硬着头皮写了个单线程的。程序的大概意思如下:
/*这个是GUI类,也是程序的main入口类*/
class QuestionGUI extends JFrame{
private JTextArea textArea = null;
private JButton button = null;
...... public QuestionGUI(){
//组件初始化
init();
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//当事件触发时进行处理
doProceed();
}
}
} public void init(){
//初始化TextArea和Button
textArea = new JTextArea("",6,19);
button = new JButton("ok");
......
}
//自己实现的为textarea写入内容的打印函数
public void println(String str){
this.textArea.setText(str);
}
//处理函数,处理的具体逻辑封装在另外一个类里。
public void doProceed(){
QuestionProceed qp = new QuestionProceed(this);
qp.doSometing();
} public static void main(String[] args){
//主函数,这里我没有使用多线程
QuestionGUI qig = new QuestionGUI ();
qig.setVisiable(true);
}
}/*这是具体实现处理逻辑的类*/
class QuestionProceed{
//保存一个gui对象,用以调用println方法写textarea
private QuestionGUI gui = null; //构造函数接受gui类传来的对象
public Question(QuestionGUI gui){
this.gui = gui;
}
//具体的处理逻辑,在这里就简化为直接打印一个值
public void doSometing(){
this.gui.println("I am here!");
}
}执行这个程序的预期效果是,产生一个包含TextArea和Button的窗体,一按Button,窗体的TextAera中出现"I am here!"的字样。可是我在实现了相应的程序后,发现在IDE中调试没有问题,可是一旦打成jar包在系统中独立执行的时候,TextArea中的字就出不来。这是为什么呢?是线程的原因还是程序的结构不对?一般来说,如果要形成我想要的功能逻辑,SWING程序应该如何布局比较合理呢?望高手们指点。
數據庫沒連接上,因為環境不同。以上兩點是開發環境搬到正式環境容易發生的錯誤。
而且打印文字在Eclipse或者是Netbeans里运行都是可以显示的,仅仅是我输出成jar文件以后就无法打印了。