我想這個計劃完成到: 1:要求用戶輸入的JOptionPane的窗口 第二屆一個手機號碼:顯示消息「,單擊OK跟蹤(輸入) 3的GPS座標:只有在用戶點擊OK啓動畫面應該彈出 4:啓動畫面應該徹底完成,之後的JOptionPane的窗口應該顯示「位於內GPS地址座標是:」消息,再加上我在輸入任何假地址開機畫面順序是錯誤的
現在,啓動畫面在所有其他操作期間運行,並且全部不按順序。我希望點擊「OK」後執行啓動畫面,然後完成並繼續使用最終的JOptionPane消息。非常感謝!僅供參考 - 此程序旨在作爲假笑話。
public class SplashScreen extends JWindow {
static boolean isRegistered;
private static JProgressBar progressBar = new JProgressBar();
private static SplashScreen execute;
private static int count;
private static Timer timer1;
public SplashScreen() {
Container container = getContentPane();
container.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new javax.swing.border.EtchedBorder());
panel.setBackground(Color.green);
panel.setBounds(10, 10, 348, 150);
panel.setLayout(null);
container.add(panel);
JLabel label = new JLabel("Tracking target GPS coordinates...");
label.setFont(new Font("Verdana", Font.BOLD, 14));
label.setBounds(15, 25, 280, 30);
panel.add(label);
progressBar.setMaximum(50);
progressBar.setBounds(55, 180, 250, 15);
container.add(progressBar);
loadProgressBar();
setSize(370, 215);
setLocationRelativeTo(null);
setVisible(true);
}
private void loadProgressBar() {
ActionListener al = new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
count++;
progressBar.setValue(count);
System.out.println(count);
if (count == 300) {
createFrame();
execute.setVisible(false);
timer1.stop();
}
}
private void createFrame() throws HeadlessException {
JFrame frame = new JFrame();
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
};
timer1 = new Timer(50, al);
timer1.start();
}
public static void main(String[] args) {
execute = new SplashScreen();
String targetCell = JOptionPane.showInputDialog(null, "Enter "
+ "target cellphone number: ");
JOptionPane.showMessageDialog(null, "Click OK to "
+ "track the GPS coordinates of " + targetCell + "...");
JOptionPane.showMessageDialog(null, "The address located within "
+ "GPS coordinates is: " /** + "random fake address") **/);
}
};
因此,請勿創建「SplashScreen」實例直到你真的需要它。另外請記住,Swing不是線程安全的並且是單線程的。這意味着1-您只應從事件分派線程的上下文中更新UI,並且2-您不應該用長時間運行的任務阻止EDT – MadProgrammer