G
Gast
Gast
Hi,
ich habe folgendes Problem.
Ich habe ein Programm geschrieben, dass relativ viele aufwändige Berechnungen durchführt.
Damit der User nicht denkt, dass das Programm abgestürtzt ist, habe ich ein zweites JFrame erstellt, dass eine ProgressBar anzeigt.
Das Problem ist, die Aktualisierung der ProgressBar wird niicht durchgeführt.
Wie kann ich es machen, dass das getan wird?
So sieht die aufrufende Methode aus:
Die Progress bar sieht wie folgt aus:
Ich möchte allerdings nicht alzu viel umschreiben (z.B. durch einen thread oder process).
Gibt es eine andere Möglcihkeit?
Danke für eure Hilfe.
ich habe folgendes Problem.
Ich habe ein Programm geschrieben, dass relativ viele aufwändige Berechnungen durchführt.
Damit der User nicht denkt, dass das Programm abgestürtzt ist, habe ich ein zweites JFrame erstellt, dass eine ProgressBar anzeigt.
Das Problem ist, die Aktualisierung der ProgressBar wird niicht durchgeführt.
Wie kann ich es machen, dass das getan wird?
So sieht die aufrufende Methode aus:
Code:
PixelOfPicture[][] picture = this.picture.getActualPicture();
//initialize the progressbar
ProgressBar progress = new ProgressBar(numberOfRemovableRows , "Removing horizontal seams");
progress.setDescription(0, 0);
for(int i = 0; i < numberOfRemovableRows; i++){
try{
picture = RemoveSeam.removeSeam(picture,false);
//update the progress bar
progress.setDescription(0, i);
progress.setProgressStatus(i);
}
catch(UnableToDeleteSeamException UTDSE){
break;
}
}
progress.closeProgressbar();
this.picture.setActualPicture(picture);
Die Progress bar sieht wie folgt aus:
Code:
public ProgressBar(int maximumValue , String headline){
this.maximumValue = maximumValue;
//configure the frame
this.progressFrame = new JFrame();
this.progressFrame.setSize(400, 80);
this.progressFrame.setVisible(true);
this.progressFrame.setTitle(headline);
//configure the progress bar
this.progressBar = new JProgressBar();
this.progressBar.setMinimum(0);
this.progressBar.setMaximum(maximumValue);
this.progressBar.setValue(0);
this.progressBar.setSize(380, 15);
//configure the panel
this.progressPanel = new JPanel();
this.progressPanel.setSize(400, 30);
//configure the label
this.progressLabel = new JLabel();
//link all components
this.progressFrame.add(this.progressBar);
this.progressPanel.add(this.progressLabel);
this.progressFrame.add(this.progressPanel);
//set all positions
this.progressBar.setLocation(5, 25);
this.progressPanel.setLocation(0, 0);
this.progressLabel.setLocation((400 - this.progressLabel.getWidth())/2, 10);
//set the location of the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.progressFrame.setLocation((screenSize.width - this.progressFrame.getWidth()) / 2 ,
(screenSize.height - this.progressFrame.getHeight()) / 2);
}
public void setDescription(int description , int i){
switch(description){
case 0 : progressLabel.setText("Removed " + i + " of " + this.maximumValue + " seams"); break;
case 1 : progressLabel.setText("Added " + i + " of " + this.maximumValue + " seams"); break;
default: progressLabel.setText("No description available");
}
}
public void setProgressStatus(int status){
this.progressBar.setValue(status);
}
Ich möchte allerdings nicht alzu viel umschreiben (z.B. durch einen thread oder process).
Gibt es eine andere Möglcihkeit?
Danke für eure Hilfe.