我在GUI項目中使用eclipse中的Window Builder。我想添加一個啓動畫面用進度條轉到主頁加載達到100%之後。我得到的錯誤類型進度欄不能在運行()來解決我在一個項目中使用eclipse中的Window Builder。我正在嘗試添加啓動畫面。我得到的錯誤類型進度條無法解析
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.Color;
import javax.swing.UIManager;
import javax.swing.JProgressBar;
import javax.swing.ProgressMonitor;
import java.awt.SystemColor;
import java.sql.Connection;
import javax.swing.border.LineBorder;
import javax.swing.plaf.ProgressBarUI;
@SuppressWarnings("serial")
public class Loading extends JFrame implements Runnable{
Connection conn;
int s=0;
Thread th;
private JPanel contentPane;
/**
* Create the frame.
*/
public Loading() {
super("Loading");
th = new Thread((Runnable) this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 540, 363);
contentPane = new JPanel();
contentPane.setBorder(new LineBorder(new Color(250, 128, 114), 2));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblSmartLibrary = new JLabel("# Library");
lblSmartLibrary.setForeground(UIManager.getColor("RadioButtonMenuItem.selectionBackground"));
lblSmartLibrary.setFont(new Font("Times New Roman", Font.PLAIN, 20));
lblSmartLibrary.setBounds(225, 43, 144, 24);
contentPane.add(lblSmartLibrary);
JProgressBar progressBar = new JProgressBar();
progressBar.setValue(0);
progressBar.setStringPainted(true);
progressBar.setForeground(new Color(135, 206, 250));
progressBar.setBackground(SystemColor.window);
progressBar.setBounds(190, 151, 150, 32);
contentPane.add(progressBar);
JLabel lblPleaseWait = new JLabel("Please wait...");
lblPleaseWait.setBounds(225, 182, 88, 16);
contentPane.add(lblPleaseWait);
}
public void setupLoading(){
setVisible(false);
th.start();
}
public void run(){
try{
for (int i=1; i<= 200; i++){
s = s + 1;
//The error is Here.Type progressBar cannot be resolved
int m = progressBar.getMaximum();
int v= progressBar.getValue();
if(v<m){
progressBar.setValue(progressBar.getValue()+1);
}else{
i=201;
setVisible(false);
Home ob = new Home();
ob.setVisible(true);
}Thread.sleep(50);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Loading frame = new Loading();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
1)* 「我想添加一個啓動畫面。」 *這就是['SplashScreen'](http://docs.oracle.com/javase/8/docs/api/java/ awt/SplashScreen.html)是! 2)Java GUI必須在不同的語言環境中使用不同的PLAF來處理不同的操作系統,屏幕大小,屏幕分辨率等。因此,它們不利於像素的完美佈局。請使用佈局管理器或[它們的組合](http://stackoverflow.com/a/5630271/418556)以及[white space]的佈局填充和邊框(http://stackoverflow.com/a/17874718/ 418556)。 3)'new Font(「Times New Roman」,Font.PLAIN,20)''最好是:.. –
..'new Font(Font.SERIF,Font.PLAIN,20)' –
公平的,但如果它是一個爲了學習而鍛鍊,然後「重新發明輪子」不是*所有的邪惡。 –