swing 重绘 现在在做一个swing的画面有一个按钮是输出文件,点下之后输出时间很长,这时候在原有的画面上重绘一个小的panel可以么?输出完毕后,再把小的panel隐藏?具体怎么做,麻烦各位了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 开辟新线程,将耗时操作放到线程里完成.在主线程里爱干嘛干嘛,同时增加一个线程监控,当耗时操作完成时触发该方法将主界面刷新.over 给你一个例子import java.awt.EventQueue;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;public class Test extends JFrame { /** * Launch the application * @param args */ public static void main(String args[]) { EventQueue.invokeLater(new Runnable() { public void run() { try { Test frame = new Test(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame */ public Test() { super(); getContentPane().setLayout(null); setBounds(100, 100, 500, 375); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton(); button.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { Thread thread = new Thread(new Runnable() { public void init() { // 初始化界面,比如说画一个panel } public void update() { //更新界面,比如销毁panel } public void run() { EventQueue.invokeLater(new Runnable() { public void run() { init(); } }); //.......... // 执行输出文件的操作 //......... EventQueue.invokeLater(new Runnable() { public void run() { update(); } }); } }); thread.start();// 启动线程 } }); button.setText("New JButton"); button.setBounds(163, 137, 106, 26); getContentPane().add(button); // }} 事件派发线程Swingutility.invokeLater(); 用Swingutility.invokeLater()搞定了。谢谢各位 想做一个学生管理系统,把信息放入一个文件中,实现增删改查,不会修改和删除 JSP乱码 JPanel 设置背景图片问题 一个小时了还没解决 急死人了 如何从外部通过代码的方式关闭一个已知的JAVA程序? JCreator有一个功能使用起来很不习惯,有没有办法更改? 保持另存为对话框 java.awt.Container.validate() 这个API函数有什么作用? 关于用Socket在两台机器之间复制文件问题!1000000分送给你! 请问一下一个关于URL方面的问题 word,excel,ppt文件转成pdf文件java用什么开源程序比较好?? Java代碼輸入
在主线程里爱干嘛干嘛,同时增加一个线程监控,当耗时操作完成时触发该方法将主界面刷新.
over
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;import javax.swing.JFrame;public class Test extends JFrame { /**
* Launch the application
* @param args
*/
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test frame = new Test();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} /**
* Create the frame
*/
public Test() {
super();
getContentPane().setLayout(null);
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
Thread thread = new Thread(new Runnable() { public void init() {
// 初始化界面,比如说画一个panel
}
public void update() {
//更新界面,比如销毁panel
}
public void run() {
EventQueue.invokeLater(new Runnable() {
public void run() {
init();
}
});
//..........
// 执行输出文件的操作
//.........
EventQueue.invokeLater(new Runnable() {
public void run() {
update();
}
});
}
});
thread.start();// 启动线程
}
});
button.setText("New JButton");
button.setBounds(163, 137, 106, 26);
getContentPane().add(button);
//
}}
谢谢各位