Topic: 请教一个关于swing界面刷新的问题。 |
Print this page |
1.请教一个关于swing界面刷新的问题。 | Copy to clipboard |
Posted by: pilgrimhuyu Posted on: 2003-05-19 11:35 我想要点击jButton1后jLabel1、jLabel2作一个计数显示,但jLabel1只显示最后的结果,没有刷新的过程,是不是jLabel1的双缓存在作用。请高手指教。谢谢! import javax.swing.*; import com.borland.jbcl.layout.*; import java.awt.*; import java.awt.event.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */ public class Test extends JFrame { XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JButton jButton1 = new JButton(); public Test() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { Test test = new Test(); test.pack(); } private void jbInit() throws Exception { jLabel1.setText("jLabel1"); this.getContentPane().setLayout(xYLayout1); jLabel2.setText("jLabel2"); jLabel1.setDoubleBuffered(true); jLabel2.setDoubleBuffered(true); jButton1.setText("jButton1"); jButton1.addActionListener(new Test_jButton1_actionAdapter(this)); this.getContentPane().add(jLabel1, new XYConstraints(48, 48, 111, 41)); this.getContentPane().add(jLabel2, new XYConstraints(200, 45, 122, 44)); this.getContentPane().add(jButton1, new XYConstraints(42, 129, 93, 44)); this.pack(); this.setVisible(true); } void jButton1_actionPerformed(ActionEvent e) { for (int i = 0; i < 10000; i++) { jLabel1.setText("1: " + i); jLabel2.setText("1: " + i); jLabel1.repaint(); jLabel2.repaint(); this.repaint(); } } } class Test_jButton1_actionAdapter implements java.awt.event.ActionListener { Test adaptee; Test_jButton1_actionAdapter(Test adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed; } } |
2.Re:请教一个关于swing界面刷新的问题。 [Re: pilgrimhuyu] | Copy to clipboard |
Posted by: yakuu Posted on: 2003-05-19 20:21 please use thread. for more detail, take a look at http://sourceforge.net/projects/foxtrot |
3.Re:请教一个关于swing界面刷新的问题。 [Re: pilgrimhuyu] | Copy to clipboard |
Posted by: pilgrimhuyu Posted on: 2003-05-21 10:48 谢谢!我用您指点的foxtrot已经解决这个问题了。 |
4.Re:请教一个关于swing界面刷新的问题。 [Re: pilgrimhuyu] | Copy to clipboard |
Posted by: ww2003 Posted on: 2003-05-22 11:07 要强制进行刷新,调用revalidate()和repaint()方法 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |