Results 1 to 4 of 4
- 11-23-2008, 06:20 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
[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 (?)
The button which start the TaskJava 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); } } }); }
And the Task itselfJava Code:private void startButtonActionPerformed(java.awt.event.ActionEvent evt) { this.startEncrypt().execute; }
Theorically the TaskMonitor should react when a new Task occurs :confused:Java 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() { } }
I must be missing something :rolleyes:
Any help will be more than welcome! ;)
-Sebastien
- 11-23-2008, 06:37 PM #2
how to determine task length?
Okay, so how do we determine how long RSA will take on this:
Not being difficult, it is just that I do not see how we can set some upper bound for task completion ...Java 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."}, {" }"}, {"}"}, };Last edited by Nicholas Jordan; 11-23-2008 at 07:03 PM.
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 11-23-2008, 09:15 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
Well I'm not sure what you're talking about but I though that this code generated by netbeans for a Desktop Application should follow the task progress and update the progress bar:
I might be wrong, and if it's the case, any idea how to do it?Java Code: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); } } });
Thanks
- 11-27-2008, 11:00 PM #4
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
The task wasn't actually recognized by the TaskMonitor, here is what I've done
The button which start the Task
And the TaskJava Code:private void startButtonActionPerformed(java.awt.event.ActionEvent evt) { this.startEncrypt(); }
Hope that can help :cool:Java Code:@Action public Task startEncrypt() { StartEncryptTask task = new StartEncryptTask(org.jdesktop.application.Application.getInstance()); ApplicationContext C = getApplication().getContext(); TaskMonitor M = C.getTaskMonitor(); TaskService S = C.getTaskService(); S.execute(task); M.setForegroundTask(task); return task; } 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() { } }
Similar Threads
-
Deployment of JRE 6 u7 to desktop pc / Configuration
By rrathbun in forum New To JavaReplies: 0Last Post: 09-12-2008, 08:37 PM -
three tier Desktop Application
By newmember in forum AWT / SwingReplies: 0Last Post: 07-27-2008, 03:10 PM -
Desktop search in java
By hellosubs in forum New To JavaReplies: 0Last Post: 06-15-2008, 03:33 PM -
Spliting desktop
By nagarte in forum AWT / SwingReplies: 5Last Post: 05-05-2008, 12:56 PM -
k5n Desktop Calendar 0.9.0
By levent in forum Java SoftwareReplies: 0Last Post: 06-02-2007, 07:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks