[SOLVED] Netbeans Desktop App & JProgressBar
Hi everyone,
I've been looking for solutions for my problem on the internet for hours without any success so I hope someone here can help me.
I'm working on an encryption program on Java implementing the RSA algorithm.
I'm using a NetBeans Desktop Application to develop this application.
Since the encryption process might take a while depending on which files the user wants to encrypt, I'm using a Task that realizes the process in another thread within the doInBackground() method.
Everything works fine except that I'd like to display the process progress in the progress bar provided by default in the desktop application. But for some reasons, nothing happens :(
Here is the code:
Generated by Netbeans, no need to modify it (?)
Code:
public class RSAProject extends FrameView {
public RSAProject(SingleFrameApplication app) {
super(app);
initComponents();
// status bar initialization - message timeout, idle icon and busy animation, etc
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(true);
// connecting action tasks to status bar via TaskMonitor
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
@Override
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
System.out.println(propertyName);
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
}
The button which start the Task
Code:
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
this.startEncrypt().execute;
}
And the Task itself
Code:
@Action
public Task startEncrypt() {
return new StartEncryptTask(getApplication());
}
private class StartEncryptTask extends Task<Void, Void> {
StartEncryptTask(org.jdesktop.application.Application app) {
super(app);
}
@Override
protected Void doInBackground() {
try {
//specific code for encryption
}
catch(java.lang.Exception e) {
//specific code for exceptions
}
return null;
}
protected void succeeded() {
}
}
Theorically the TaskMonitor should react when a new Task occurs :confused:
I must be missing something :rolleyes:
Any help will be more than welcome! ;)
-Sebastien
how to determine task length?
Okay, so how do we determine how long RSA will take on this: Code:
final java.lang.String[][] RevisedProgram=
{
{"class HellWorldApp extends HellWorld"},
{"{"},
{" public HelloWorldApp()"},
{" {"},
{" super();//"},
{" }"},
{" // main method, standard entry point for system to lauch application."},
{" public static void main(String[] args)"},
{" {"},
{" System.out.println(\"With blinding applied, the decryption time is no longer correlated to the value of the input ciphertext and so the timing attack fails.\"); // Display string."},
{" }"},
{"}"},
};
Not being difficult, it is just that I do not see how we can set some upper bound for task completion ...