import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class Progress extends JFrame {
JProgressBar current;
JTextArea out;     //这两个变量声明具体有什么用啊,我把它们都注释掉后了,程序执行的效果也一样的啊
JButton find;      //同上
Thread runner;
int num=0;

public Progress() {
super("Progress");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel pane=new JPanel();
pane.setLayout(new FlowLayout()); //setLayout()方法有什么用,还有他里面的new FlowLayout是什么,有什么作用
current=new JProgressBar(0,2000);
current.setValue(0);
current.setStringPainted(true);
pane.add(current);
setContentPane(pane);
}


public void iterate() {
while (num<2000) {
current.setValue(num);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
//...
}
num+=95;
}
}

public static void main(String[] args) {
Progress frame=new Progress();
frame.pack();
frame.setVisible(true);
frame.iterate();
}
}问题已经提在注释里了,大家帮忙看看。
还有我已经查过API了,只是E文看不懂。

解决方案 »

  1.   

    这些都是Jcomponent,程序里其他地方都没用到注释掉当然没关系了
      

  2.   

    还有pane.setLayout(new FlowLayout());  这句中的pane.setLayout()方法有什么用呢?还有new FlowLayout是什么,有什么作用
      

  3.   

    程序里只是声明了一个类型为JTextArea 的变量out和类型为JButton 的find
    并没有实例化所以没有没并不影响到程序setLayout()是用来设置布局的
    FlowLayout只是多种布局中的一种,还有BorderLayout,GridLayout等等
      

  4.   

    Layout是布局管理器,有很多种的,flowlayout是最简单的一种,好好看看吧