[align=center]JProgressBar progressBar;
progressBar = new JProgressBar();
progressBar.setStringPainted(true);如在MAIN里有调用了A的CALSS里的函数C(),在C()里如何把JProgressBar 的百分比改变?
import XXX.XXX.a;
a q = new a();
a.C()的函数是完成计算的过程,而我想用JProgressBar 来显示C()完成的进度!!我应该怎办??[/align]

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【jackwin】截止到2008-07-11 16:46:46的历史汇总数据(不包括此帖):
    发帖的总数量:8                        发帖的总分数:325                      每贴平均分数:40                       
    回帖的总数量:11                       得分贴总数量:1                        回帖的得分率:9%                       
    结贴的总数量:8                        结贴的总分数:325                      
    无满意结贴数:1                        无满意结贴分:30                       
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:100.00%                  
    无满意结贴率:12.50 %               无满意结分率:9.23  %                  
    敬礼!
      

  2.   

    具体方法是progressBar.setValue(一个整数)
    至于怎么调你自己看着办,因为你的代码逻辑只有你最清楚
      

  3.   

    比较好的办法是使用“事件-监听器”机制比较简单但是不推荐的方式是将 JProgressBar 作为参数传递给 a.C
    在 a.C 里调用JProgressBar的方法setValue动态修改
      

  4.   

    Craky这个progressBar.setValue(一个整数) 当然知道LexChen 的事件-监听器?
      

  5.   

    嗯,让A这个类在需要更改进度条的时候抛出一个事件,事件里包含了新
    的进度信息,在实例化A的一个对象a后,给a增加一个监听器,同时包含进度条的类
    实现了a的监听器的监听方法,在监听方法里根据进度信息更新进度条显示呵呵,简单说就是这样。就是这个板块,很久以前有篇标题“对Swing线程的再思索”的文章说的比较清楚
    不知道还能不能查到
      

  6.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class LoginProgressFrame extends JDialog implements Runnable { 
    private JProgressBar bar;
    private Container me;
    private JLabel lblBackground;
    private JLayeredPane layPane;
    private JLabel lblTitle;
    private Thread thread;
    private String userName;
    Random random = new Random();
    public LoginProgressFrame(String userName) {
    init();
    this.userName = userName;
    this.setSize(400,300);
    this.setUndecorated(true);//没有标题栏
    this.setLocationRelativeTo(null);
    this.setResizable(false);
    this.setVisible(true);
    }
    public void init() {

    lblBackground = new JLabel(new ImageIcon("image/login.jpg"));
    me = (JPanel) getContentPane();
            me.setLayout(new BorderLayout());
            me.add(lblBackground);
            setSize(new Dimension(400,300));
    bar = new JProgressBar();
    bar.setForeground(Color.blue);
    bar.setBounds(50,200,300,40);
    bar.setStringPainted(true);//设置进度条字
    lblTitle = new JLabel("欢迎使用本系统");
    lblTitle.setBounds(50,50,280,30);
    layPane = this.getLayeredPane();
    layPane.add(bar);
    layPane.add(lblTitle);
    thread = new Thread(this);
    thread.start();
    }
    public void run() {
    while(bar.getValue() < bar.getMaximum()) {
    bar.setValue(bar.getValue() + random.nextInt(10));
    try {
    thread.sleep(200);
    }catch(InterruptedException ie) {
    ie.printStackTrace();
    }
    }
    this.dispose();
    new MainFrame(userName);
    }
    }
    用线程加随机数来控制
      

  7.   

    lexchen说的是java推荐的方法.使用硬编码进行修改会使程序的结构很乱