我有一个将文件(通过 ADB)复制到 android 平板电脑的应用程序。这需要一些时间,所以我想显示一个带有不确定进度条的弹出窗口。复制任务完成后,我希望能够停止进度条并让用户关闭对话框。
目前我还没有添加额外的对话框,只是想让进度条正常工作。我遇到的问题是任务开始时没有显示进度条,但我不知道为什么。当出现同步完成对话框时会显示进度条。代码是:
progress = new JProgressBar(0, 100);
progress.setForeground(new Color(255, 99, 71));
progress.setIndeterminate(true);
progress.setValue(0);
progress.setPreferredSize( new Dimension( 300, 20 ) );
progress.setBounds( 278, 12, 260, 20 );
progress.setVisible(false);
progress.setString("Sync in progress");
progress.setStringPainted(true);
contentPane.add(progress);
pushtotab = new JButton("");
pushtotab.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (buildpathset==1){
try{
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
progress.setVisible(true);
wiredsync();
}finally{
JOptionPane.showMessageDialog(null, "sync complete. ",null, buildpathset);
setCursor(Cursor.getDefaultCursor());
progress.setVisible(false);
}}else{
//warning in here later - TO Do
}
}
});
public void wiredsync(){
try {
Process process = Runtime.getRuntime().exec("adb" + " push "+ buildpath + " " + adbtabletsync);
InputStreamReader reader = new InputStreamReader(process.getInputStream());
Scanner scanner = new Scanner(reader);
scanner.close();
int exitCode = process.waitFor();
System.out.println("Process returned: " + exitCode);
} catch(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}//end
谢谢您的帮助,
安迪