在我正在开发的应用程序中,当点击“转换”按钮时需要显示进度条,以下是我的代码,
public class Main extends JFrame{
private JPanel panel2 = null;
private JPanel panel2 = null;
JProgressBar progressBar = null;
JButton button = null;
Main f1 = null;
Main f = null;
public static void main(String[] args) {
try
{
UIManager.setLookAndFeel(new SyntheticaBlackEyeLookAndFeel());
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void convert(){
f = new Main();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(700, 400);
f.setLocationRelativeTo(null);
f.setTitle("Fromat Conversion");
panel1 = new JPanel();
panel1.setLayout(new BorderLayout());
panel1.setForeground(Color.white);
button = new JButton();
button.setText("Convert");
panel1.add(panel3, BorderLayout.SOUTH);
f.setContentPane(panel1);
f.setVisible(true);
f1 = new Main();
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setSize(457, 100);
f1.setTitle("Conversion Progress");
f1.setLocationRelativeTo(null);
panel2 = new JPanel();
panel2.setLayout(new BorderLayout());
panel2.setForeground(Color.white);
progressBar = new JProgressBar();
progressBar.setValue(35);
progressBar.setStringPainted(true);
panel2.add(label3, BorderLayout.WEST);
panel2.add(progressBar, BorderLayout.SOUTH);
f1.setContentPane(panel2);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
f1.setVisible(true);
}
});
}
}
但是当我点击按钮时,进度条框不会显示。
任何人都知道为什么会这样?
谢谢
答案 0 :(得分:1)
您的代码无法编译。
这实际上会编译并显示您的进度条。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Pipo extends JFrame{
private static JPanel panel1 = null;
private static JPanel panel2 = null;
static JProgressBar progressBar = null;
static JButton button = null;
static Pipo f1 = null;
static Pipo f = null;
public static void main(String[] args) {
f = new Pipo();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(700, 400);
f.setLocationRelativeTo(null);
f.setTitle("Fromat Conversion");
panel1 = new JPanel();
panel1.setLayout(new BorderLayout());
panel1.setForeground(Color.white);
button = new JButton();
button.setText("Convert");
panel1.add(button, BorderLayout.SOUTH);
f.setContentPane(panel1);
f.setVisible(true);
f1 = new Pipo();
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setSize(457, 100);
f1.setTitle("Conversion Progress");
f1.setLocationRelativeTo(null);
panel2 = new JPanel();
panel2.setLayout(new BorderLayout());
panel2.setForeground(Color.white);
progressBar = new JProgressBar();
progressBar.setValue(35);
progressBar.setStringPainted(true);
panel2.add(progressBar, BorderLayout.SOUTH);
f1.setContentPane(panel2);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
f1.setVisible(true);
}
});
}
}