作者:泉怪的皮毛_884 | 来源:互联网 | 2023-05-19 05:30
WhatIwanttodoistoshowanewpanelwithaprogressbarwhiletheprocesstakesplace.我想要做的是在
What I want to do is to show a new panel with a progress bar while the process takes place.
我想要做的是在进程发生时显示带有进度条的新面板。
My code is as follows:
我的代码如下:
case "GoButton":
cards.show(this, "pp");
this.test();
cards.show(this, "panel1");
break;
That is in a actionPerformed
method
这是在actionPerformed方法中
but when I run the program it just ignores the first cards.show
, it executes the test
code and then it executes the second cards.show
但是当我运行程序时它只是忽略了第一个cards.show,它执行测试代码,然后执行第二个cards.show
I also provide you the rest of the code in case you need it
如果您需要,我还会为您提供其余的代码
public CreatePanel(JFrame frame) {
ext = new ArrayList<>();
files = new ArrayList<>();
this.mainWindow = frame;
this.setSize(256, 256);
cards = new CardLayout();
this.setLayout(cards);
panel1 = new JPanel(null);
createPanel1(panel1);
this.add(panel1, "panel1");
panel2 = new JPanel(null);
createPanel2(panel2);
this.add(panel2, "panel2");
panel3 = new JPanel(null);
createPanel3(panel3);
this.add(panel3, "pp");
cards.show(this, "panel1");
}
public class ProgressPanel {
private static JPanel panel;
private static JProgressBar progressBar;
private static int progress;
public static JPanel createProgressPanel(){
ProgressPanel.panel = new JPanel(null);
ProgressPanel.initPanel();
return ProgressPanel.panel;
}
private static void initPanel(){
panel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
progressBar = new JProgressBar(0, 100);
progressBar.setValue(progress);
progressBar.setStringPainted(true);
panel.add(progressBar, c);
}
public static void updateProgress(int x){
ProgressPanel.progress += x;
}
public void resetProgress(){
this.progress = 0;
}
}
1 个解决方案