Advertisement
Guest User

RCReminder.java

a guest
Oct 14th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package rcreminder;
  6. import java.io.File;
  7. import java.io.FileReader;
  8. import java.io.BufferedReader;
  9. import javax.swing.JOptionPane;
  10. import java.util.Timer;
  11. import java.util.TimerTask;
  12.  
  13. /**
  14.  *
  15.  * @author DenyingBelial
  16.  */
  17. public class RCReminder {
  18.  
  19.     public static int TimerMS = 0;
  20.     public static String Message = "";
  21.     public static final Timer t = new Timer("Reminder");
  22.     /**
  23.      * @param args the command line arguments
  24.      */
  25.     public static void main(String[] args) {
  26.         // TODO code application logic here
  27.        
  28.         loadConfig();
  29.        
  30.        
  31.         TimerTask showMessage = new TimerTask(){
  32.             public void run(){
  33.             JOptionPane.showMessageDialog(null, Message, "Reminder", 1);
  34.             }
  35.         };
  36.         t.schedule(showMessage, 0, TimerMS);
  37.        
  38.        
  39.     }
  40.    
  41.     public static void loadConfig(){
  42.         try{
  43.             File configF = new File("./conf.ini");
  44.             if(!configF.exists()){configF.createNewFile();}
  45.        
  46.             FileReader configStream = new FileReader(configF);
  47.             BufferedReader configBuf = new BufferedReader(configStream);
  48.             String configString = configBuf.readLine();
  49.             while(configString!=null){
  50.                
  51.                 if(configString.contains("Timelapse=")){
  52.                     String timeVal = configString.substring("Timelapse=".length());
  53.                     TimerMS = Integer.parseInt(timeVal);
  54.                    
  55.                 }
  56.                 if(configString.contains("Message=")){
  57.                     String messVal = configString.substring("Message=".length());
  58.                     Message = messVal;
  59.                    
  60.                 }
  61.                 configString = configBuf.readLine();
  62.            
  63.             }
  64.         }
  65.         catch(Exception e){
  66.             JOptionPane.showMessageDialog(null, "Error loading config file. "
  67.                     + "Please verify that the file exists and you have RW "
  68.                     + "permission. \n"+ e.toString(), "Error", 1);
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement