我的代碼如下不工作,任何人都可以告訴我爲什麼?請更正我的代碼,我對Java很新。除此之外,我正在尋找「加載面板組件」,類似ProgressMonitor
,但可能更具吸引力並且動畫效果更好。如果有人曾經使用過這種東西,請告訴我。Java ProgressMonitor不工作
public class Main extends JFrame {
private JPanel contentPane;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
ProgressMonitor pm = new ProgressMonitor(frame, "Loading...",
"waiting...",
0, 100000);
for (int i = 0 ; i < 100000 ; i ++){
pm.setProgress(i);
pm.setNote("Testing");
System.out.println(i);
Thread.sleep(1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
}
}
你的答案是最好的!汗水,終於我設法經過長時間的努力才得以實現。 – GMsoF 2012-07-21 11:25:33