A Project Run@Timer, J2SE,

442 views
327 views

Published on

RUN@TIMER is an application created by me on pure innovation concept. And I am glad to announce that I was asked a number of questions on it, but I passed it all and hoping for good marks now!

Published in: Engineering, Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
442
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

A Project Run@Timer, J2SE,

  1. 1. Saurabh Jain Assistant. Professor,CSE OCT BHOPAL ORIENTAL COLLEGE OF TECHNOLOGY, BHOPAL (Formerly known as Thakral College of Technology, Bhopal) Approved by AICTE New Delhi & Govt. of M.P. and Affiliated to Rajiv Gandhi Proudyogiki Vishwavidhyalaya Bhopal (M.P.) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING CERTIFICATE This is to Certify that the Minor Project Entitled “Run@Timer” Being Submitted By Swapnil Dubey and Radhika Shrivastava in Partial fulfillment of the Requirement for the Award Of B.E Degree In Computer Science & Engineering To Oriental College Of Technology, Bhopal(M.P) is a Record Of Bonafide work done by her under my Guidance. Prof. Rachana Mishra Head of Department, CSE OCT BHOPAL
  2. 2. Page | - 2 - ACKNOWLEDGEMENT I am heartily thankful to the Management of Oriental College of Technology for providing me all the facilities and infrastructure to take my work to the final stage. I would like to express my deep sense of respect and gratitude towards my advisor and guide Saurabh Jain, A.P,CSE Deptt. Oriental College of Technology, Bhopal who has given me an opportunity to work under him. He has been a constant source of inspiration throughout my work. His invaluable knowledge and innovative ideas helped me to take the work to the final stage. I express my respect to Dr. Kavita Burse, Director, Oriental College of Technology for her constant encouragement and invaluable advice in every aspect of my academic life. I would like to express my sincere thanks to Prof. Rachana Mishra, Head, Computer Science Engineering Department, Oriental College of Technology and all faculty members of Computer Science and Engineering Department for their support and guidance. I am especially thankful to our Parents and our siblings for their love, sacrifice and support on every path of my life.. Last but not the least I am extremely thankful to all who have directly or indirectly helped me for the completion of my work.
  3. 3. Page | - 3 - INDEX 1.Abstract…………………………………….. 2.Introduction………………………………… 3.Brief explanation……………………………….. 4.Software requirement specification………….. i) Requirement ii) Hardware iii) Scope iv) Tools used 5. Software engineering methods used…….. 6. Related and proposed scenario……………. 7. Limitations and further scope…………….. 8. Source codes snapshots……………………… 9. Conclusions…………………………………. 10. References……………………………………
  4. 4. Page | - 4 - ABSTRACT We now a days are so busy in handling things on our computer systems that we often miss a task during our work, and then realize after sometime that if we’d have done this task results would have been different. That’s where the application developed by me and my team comes into existence. Run@timer is a timer application developed in J2SE platform and takes time and task to be done as input and then at given time performs that task. This project report intends to give an overview of Run@Timer, its uses and techniques. It also attempts to identify the requirements of a good algorithm to be followed and briefly reflects on which methods to be used to make a good project on this topic and which techniques are more suitable for which application.
  5. 5. Page | - 5 - INTRODUCTION Timer in Java is a utility class which is used to schedule tasks for both one time and repeated execution. Timer is similar to alarm facility many people use in mobile phone. Just like you can have one time alarm or repeated alarm, you can use java.util.Timer to schedule one time task or repeated task. In fact we can implement a Reminder utility using Timer in Java and that's what we are going to see in this example of Timer in Java. Two classes java.util.Timer and java.util.TimerTask is used to schedule jobs in Java and forms Timer API. TimerTask is actual task which is executed by Timer. Similar to Thread in Java, TimerTask also implements Runnable interface and overrides run method to specify task details. Timer and TimerTask example in Java Timer in Java is a utility class form java.util package which provides facility to schedule task at any time in future.
  6. 6. Page | - 6 - As I said earlier, Timer is analogues to alarm clock you setup in your smartphone. Just like alarm can be either one time or recurring, You can also schedule task for one time and recurring time interval using Timer API. Timer provides method to schedule Task where task is instance of TimerTask class, which implements Runnable interface and overrides run() method to define task which is called on scheduled time.
  7. 7. Page | - 7 - SYNOPSIS Project Name: RUN@TIMER Project Members: This Project is done in a group of two people. Project members are: 1.Swapnil Dubey 2.Radhika Shrivastava
  8. 8. Page | - 8 - BRIEF EXPLANATION What is Timer and Timertask() in Java? Timer class in Java maintains a background Thread (this could be either daemon thread or user thread, based on how you created your Timer object), also called as timer's task execution thread. For each Timer there would be corresponding task processing Thread which run scheduled task at specified time. If your Timer thread is not daemon then it will stop your application from exits until it completes all schedule task. Its recommended that TimerTask should not be very long otherwise it can keep this thread busy and not allow other scheduled task to get completed. This can delay execution of other scheduled task, which may queue up and execute in quick succession once offending task completed.
  9. 9. Page | - 9 - Difference between Timer and TimerTask in Java: As seen , I have seen programmers getting confused between Timer and TimerTask, which is quite unnecessary because these two are altogether different. You just need to remember: 1) Timer in Java schedules and execute TimerTask which is an implementation of Runnable interface and overrides run method to defined actual task performed by that TimerTask. 2) Both Timer and TimerTask provides cancel() method. Timer's cancel() method cancels whole timer while TimerTask's one cancels only a particular task. I think this is the wroth noting difference between Timer and TimerTask in Java.
  10. 10. Page | - 10 - Canceling Timer in Java Now talking about the cancelation of Timer task in java, You can cancel Java Timer by calling cancel() method of java.util.Timer class, this would result in following: 1)Timer will not cancel any currently executing task. 2)Timer will discard other scheduled task and will not execute them. 3)Once currently executing task will be finished, timer thread will terminate gracefully. 4) Calling Timer.cancel() more than one time will not affect. second call will be ignored. In addition to cancelling Timer, You can also cancel individual TimerTask by using cancel() method of TimerTask itself.
  11. 11. Page | - 11 - Important points on Timer and TimerTask in Java Now as we have got a knowledge about Timer and TimerTask in Java, we need to remember the following points: 1.One Thread will be created corresponding ot each Timer in Java, which could be either daemon or user thread. 2.You can schedule multiple TimerTask with one Timer. 3.You can schedule task for either one time execution or recurring execution. 4.TimerTask.cancel() cancels only that particular task, while Timer.cancel() cancel all task scheduled in Timer. 5.Timer in Java will throw IllegalStateException if you try to schedule task on a Timer which has been cancelled or whose Task execution Thread has been terminated.
  12. 12. Page | - 12 - When there is a need to trigger a task automatically based on time we should schedule it using a timer api. The requirement can vary from a single execution on a fixed time to high complex recurring event. For example take our regular alarm clock where we fix a time and it beeps coming day on the fixed time. Similarly a high complex example would be the MS outlook where we can schedule events with a different combination. Following are the things in consideration When does the event starts (first time) execution – It may be a day / date / time in future. Is it a one time event or a recurring event? If recurring, what is the periodicity? – In recurrence there are two types, like all the events will be on a fixed time which is planned at the time of scheduling. It may be daily / weekly / monthly / yearly / a day of a week / alternate days / only working days. Second type is, the recurring event can start after the completion of previous occurrence. There can be a delay between events.
  13. 13. Page | - 13 - When does it end, after a constant number of executions or after a time is reached like till Friday only. java.util.Timer and TimerTask : It gives facility to schedule a task for future execution in a background thread. Task can be scheduled for single or recurring execution. In recurrence, consecutive tasks will have regular intervals. Timer has got a cancel method using which all the scheduled tasks can be cancelled. Timer can be chosen to run as a daemon thread. It can be scheduled to start with respect to current time using fixed-delay. TimerTask is a thread handle using which we register tasks with the timer.
  14. 14. Page | - 14 - Important Variations: This api provides two important variations that needs to be noted. Fixed-delay Each task execution is scheduled relative to the actual execution time of the previous execution. So what is actual execution? This says that, there is no guarantee that the task will be executed at the pre-planned time and it may be delayed due to garbage collection or some background activity. We should also not confuse with triggering of task and completion of task. Triggering is the moment at which the Timer fires start a task. If a thread is asked to send email, it may wait for access to the resource like mail server. Only after the email is sent this task is considered to be completed. We need to have this duration in mind when we schedule recurrence tasks. If the recurrence time is shorter and already the previous task is not completed, the subsequent tasks will join the queue.
  15. 15. Page | - 15 - Fixed-rate Here each recurring tasks are scheduled relative to the start time of the timer. If there is any delay in execution subsequent executions will occur in quick succession to catch up with the original scheduled time. In previous case, subsequent execution will depend on just previous execution time.
  16. 16. Page | - 16 - Project scope: This project is developed for anybody who is busy doing multiple tasks on his system and wants an application to run at a specific time but has a chance that he might not remember to start it. Hence by using it he can save his time, remain stress free, do his work and leave rest on our developed application. Methodology: User needs to run the application. The user has a option of “select file/Program” he wants to run at the specific time. If the user successfully selects it, the application asks him the time at which he want to run that file/program. And after desired value when he clicks OK then the timer starts and then after desired time given by user the selected file/program execution takes place .
  17. 17. Page | - 17 - Software Requirements:  Netbeans Hardware Requirements:  Processor: Preferably 1.0 GHz or greater.  RAM: 512 MB or Greater Future Enhancements: To make it available at Windows Market so that the common people can also use it and take maximum benefit of this application.
  18. 18. Page | - 18 - SCREENSHOTS OF WORKING APPLICATION(USER MANUAL) : 1.When the application starts it looks like this. User sees a window in which the name of application Run@timer is displayed and also option to Select file /Program is there. The look and feel of the application is made very easy to use and user friendly.
  19. 19. Page | - 19 - 2.Then to start the application, user has to click the Select File/Program button.
  20. 20. Page | - 20 - 3.As soon as the user clicks the button, a File chooser window opens and we select file.
  21. 21. Page | - 21 - 4.When we open it we can browse anywhere for file in the computer. As in this example user is selecting music folder and then a song from that folder.
  22. 22. Page | - 22 -
  23. 23. Page | - 23 - 5.As soon as he clicks the open button, he returns to the main window and then he is asked to put the timer.
  24. 24. Page | - 24 - 6.The user selects the time, as in this example , he selected 1 minute:
  25. 25. Page | - 25 - 7.Then he clicks Strt which is the button ehich starts the timer of the application:
  26. 26. Page | - 26 - 8.The timer starts and the second window opens where he can see the time getting reduced second by second:
  27. 27. Page | - 27 -
  28. 28. Page | - 28 -
  29. 29. Page | - 29 - 9.When the timer time which was given by user completes, a message is displayed which says successfully executed and then, we get this screen.
  30. 30. Page | - 30 - 10.As the user selected the song , we can see that the song is played as soon as the time completes.
  31. 31. Page | - 31 - Coding Screenshots to prove the project is a pure innovational concept and is not copied from anywhere: For the first frame: 1.
  32. 32. Page | - 32 -
  33. 33. Page | - 33 -
  34. 34. Page | - 34 - For the second frame:
  35. 35. Page | - 35 -
  36. 36. Page | - 36 -
  37. 37. Page | - 37 -
  38. 38. Page | - 38 -
  39. 39. Page | - 39 - Detailed and clear coding for the first Frame of application: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author swapnil dubey */ import java.awt.Desktop; import java.awt.Toolkit; import java.awt.event.WindowEvent; import java.io.File; import java.net.URL; import javax.swing.JFileChooser; import javax.swing.JOptionPane; public class FirstFrame extends javax.swing.JFrame { /** * Creates new form FirstFrame */ public FirstFrame() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jSpinner1 = new javax.swing.JSpinner(); jSpinner2 = new javax.swing.JSpinner();
  40. 40. Page | - 40 - jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_O N_CLOSE); jLabel1.setFont(new java.awt.Font("Lucida Sans", 1, 48)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 0, 0)); jLabel1.setText("Run@timer"); jButton1.setText("Select File/Program"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jSpinner1.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1))); jSpinner2.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(5))); jLabel2.setText("minutes"); jLabel3.setText("hours"); jButton2.setFont(new java.awt.Font("Times New Roman", 1, 48)); // NOI18N jButton2.setForeground(new java.awt.Color(255, 0, 102)); jButton2.setIcon(new javax.swing.ImageIcon("C:Usersswapnil dubeyDesktopicon-start-play-128.png")); // NOI18N jButton2.setText("Start"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });
  41. 41. Page | - 41 - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L EADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.A lignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(130, 130, 130) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(40, 40, 40) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 385, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButton1)) .addGroup(layout.createSequentialGroup() .addGap(153, 153, 153) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(115, 115, 115) .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(26, 26, 26) .addComponent(jLabel2) .addGap(43, 43, 43) .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(32, 32, 32) .addComponent(jLabel3))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L EADING) .addGroup(layout.createSequentialGroup()
  42. 42. Page | - 42 - .addGap(46, 46, 46) .addComponent(jLabel1) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.A lignment.BASELINE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.A lignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(83, 83, 83) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.A lignment.TRAILING) .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2))) .addGroup(layout.createSequentialGroup() .addGap(85, 85, 85) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.A lignment.TRAILING) .addComponent(jLabel3) .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RE LATED, 73, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(27, 27, 27)) ); pack(); }// </editor-fold>//GEN-END:initComponents public void close(){ WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wi nClosingEvent);
  43. 43. Page | - 43 - } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showOpenDialog(null); if (returnValue== JFileChooser.APPROVE_OPTION) { File file=fileChooser.getSelectedFile(); jTextField1.setText(file.getAbsolutePath()); ff=jTextField1.getText(); } }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed if("".equals(jTextField1.getText())) { JOptionPane.showMessageDialog(this, "Select a file or process first", "Warning", JOptionPane.ERROR_MESSAGE); } else{ close(); int mins=Integer.valueOf(jSpinner1.getValue().toString()); int hours=Integer.valueOf(jSpinner2.getValue().toString()); int tot=(hours*60)+mins; if(tot==0) JOptionPane.showMessageDialog(this, "Timer can't be Zero", "Warning", JOptionPane.ERROR_MESSAGE); else { seconds=60*tot; SecondFrame form= new SecondFrame(); form.setLocationRelativeTo(null); form.setVisible(true); } } }//GEN-LAST:event_jButton2ActionPerformed /** * @param args the command line arguments */ static String ff; static int seconds;
  44. 44. Page | - 44 - public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel /plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(FirstFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(FirstFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(FirstFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(FirstFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new FirstFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN- BEGIN:variables
  45. 45. Page | - 45 - private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JSpinner jSpinner1; private javax.swing.JSpinner jSpinner2; private javax.swing.JTextField jTextField1; // End of variables declaration//GEN-END:variables }
  46. 46. Page | - 46 - Detailed coding for the second Frame: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.awt.Desktop; import java.io.File; import java.io.IOException; import java.util.Timer; import java.util.TimerTask; /** * * @author swapnil dubey */ public class SecondFrame extends javax.swing.JFrame { /** * Creates new form SecondFrame */ public SecondFrame() { initComponents(); startime(); } TimerTask task = new SecondFrame.RunMeTask1(); Timer timer = new Timer(); public void startime() { jTextField1.setText(s); timer.schedule(task, 0,1000); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane();
  47. 47. Page | - 47 - jTextField1 = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_C LOSE); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N jLabel1.setText("To Run"); jScrollPane1.setViewportView(jTextField1); jButton1.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N jButton1.setForeground(new java.awt.Color(255, 0, 102)); jButton1.setIcon(new javax.swing.ImageIcon("C:Usersswapnil dubeyDesktopcancel_red.png")); // NOI18N jButton1.setText("Stop"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L EADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.A lignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addGap(32, 32, 32) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(71, 71, 71)
  48. 48. Page | - 48 - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 385, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(166, 166, 166) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(44, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L EADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.A lignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(73, 73, 73) .addComponent(jLabel1)) .addGroup(layout.createSequentialGroup() .addGap(50, 50, 50) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(74, 74, 74) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RE LATED, 47, Short.MAX_VALUE) .addComponent(jButton1) .addGap(35, 35, 35)) ); pack(); }// </editor-fold>//GEN-END:initComponents FirstFrame steg = new FirstFrame(); String s=steg.ff; private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed timer.cancel(); jLabel2.setText("Stopped"); }//GEN-LAST:event_jButton1ActionPerformed public class RunMeTask1 extends TimerTask { int seconds=steg.seconds;
  49. 49. Page | - 49 - public void run() { if (seconds > 0) { int r=seconds/60; int rem=seconds%60; int hr=r/60; int rr=r%60; if(r==0) { jLabel2.setText(seconds + " secs Remaining"); seconds--; } else if(hr==0) { jLabel2.setText(r+" Mins and "+rem+" secs Remaining"); seconds--; } else { jLabel2.setText(hr+" hours "+rr+" Mins and "+rem+" secs Remaining"); seconds--; } } else if(seconds==-1) { return; } else if(seconds==0) { try{ File f = new File(s); Desktop dt = Desktop.getDesktop(); dt.open(f); }catch(IOException e){ e.printStackTrace(); } jLabel2.setText(" Successfully Executed "); seconds=-1; //System.exit(0); } }
  50. 50. Page | - 50 - } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel /plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(SecondFrame.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(SecondFrame.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(SecondFrame.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(SecondFrame.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SecondFrame().setVisible(true); } }); }
  51. 51. Page | - 51 - // Variables declaration - do not modify//GEN- BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField jTextField1; // End of variables declaration//GEN-END:variables }
  52. 52. Page | - 52 - Detailed coding for main class : /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author swapnil dubey */ public class main { /** * @param args the command line arguments */ public static void main(String[] args) { FirstFrame form=new FirstFrame (); form.setLocationRelativeTo(null); form.setVisible(true); } }
  53. 53. Page | - 53 - Conclusion: Applications like this should be developed more frequently so that more amount of work can be done in a short span of time and not worrying anything about the upcoming tasks.
  54. 54. Page | - 54 - Refrences: www.google.com www.wickepedia.org www.examples.codegeeks.com/core-java www.javarevisited.blogspot.in www.mkyong.com/java

×