这个是要显示界面的代码
package bar;import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar; public class ProgressPane extends JPanel { public JLabel label;
public JProgressBar progressBar;
public ProgressPane() {
super();
setLayout(new GridBagLayout());
setSize(394, 33); progressBar = new JProgressBar(0,100);
progressBar.setStringPainted(true);
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.weightx = 1.0;
gridBagConstraints.ipady = 10;
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.ipadx = 75;
gridBagConstraints.insets = new Insets(4, 0, 0, 0);
add(progressBar, gridBagConstraints);
label = new JLabel();
final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
gridBagConstraints_1.gridx = 1;
gridBagConstraints_1.gridy = 0;
gridBagConstraints_1.ipadx = 54;
gridBagConstraints_1.insets = new Insets(0, 12, 10, 0);
add(label, gridBagConstraints_1);
label.setText("正常状态");
//
} }
这个是主界面代码 public class mianFrame{
private JDesktopPane desktopPane;
private JFrame frame;
ProgressPane pr; public mianFrame() {
frame = new JFrame("rrrrrrr");
frame.getContentPane().setLayout(new BorderLayout());
frame.setBounds(100, 100, 700, 400);
desktopPane = new JDesktopPane();
frame.getContentPane().add(desktopPane);
JButton ckFileButton = new TJButton ("pic/check.JPG", "", "check file....", true);
ckFileButton.setBounds(350, 120, 66, 70);
desktopPane.add(ckFileButton);
pr = new ProgressPane();
pr.setBounds(350, 200, pr.getWidth(), pr.getHeight());
pr.setVisible(false);
desktopPane.add(pr);
ckFileButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
pr.setVisible(true);
getInfomation();
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new mianFrame();
}
});
}
}
我的问题是当我点击ckFileButton按钮时为什么会先运行getInfomation()最后再显示ProgressPane这个界面?而我想要要的是在运行getInformation()前就把这个界面显示出来,等到这个方法处理完后再隐藏这个界面!请问我该怎么做?谢谢!
package bar;import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar; public class ProgressPane extends JPanel { public JLabel label;
public JProgressBar progressBar;
public ProgressPane() {
super();
setLayout(new GridBagLayout());
setSize(394, 33); progressBar = new JProgressBar(0,100);
progressBar.setStringPainted(true);
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.weightx = 1.0;
gridBagConstraints.ipady = 10;
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.ipadx = 75;
gridBagConstraints.insets = new Insets(4, 0, 0, 0);
add(progressBar, gridBagConstraints);
label = new JLabel();
final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
gridBagConstraints_1.gridx = 1;
gridBagConstraints_1.gridy = 0;
gridBagConstraints_1.ipadx = 54;
gridBagConstraints_1.insets = new Insets(0, 12, 10, 0);
add(label, gridBagConstraints_1);
label.setText("正常状态");
//
} }
这个是主界面代码 public class mianFrame{
private JDesktopPane desktopPane;
private JFrame frame;
ProgressPane pr; public mianFrame() {
frame = new JFrame("rrrrrrr");
frame.getContentPane().setLayout(new BorderLayout());
frame.setBounds(100, 100, 700, 400);
desktopPane = new JDesktopPane();
frame.getContentPane().add(desktopPane);
JButton ckFileButton = new TJButton ("pic/check.JPG", "", "check file....", true);
ckFileButton.setBounds(350, 120, 66, 70);
desktopPane.add(ckFileButton);
pr = new ProgressPane();
pr.setBounds(350, 200, pr.getWidth(), pr.getHeight());
pr.setVisible(false);
desktopPane.add(pr);
ckFileButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
pr.setVisible(true);
getInfomation();
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new mianFrame();
}
});
}
}
我的问题是当我点击ckFileButton按钮时为什么会先运行getInfomation()最后再显示ProgressPane这个界面?而我想要要的是在运行getInformation()前就把这个界面显示出来,等到这个方法处理完后再隐藏这个界面!请问我该怎么做?谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货