timecount.java

package time_counter;

/**
 * 

Title: Dial up time counter

* 

Description: Time testing pergramme

* 

Copyright: Copyright (c) 2004

* 

Company: Home

* @author N.D.I.Samantha
 * @version 1.0
 */

import java.util.Date;
import java.util.Calendar;

public class timecount {
     time start_time,stop_time;

     public timecount(){
       time t= new time();
       /*System.out.println("=====time construter====");
       System.out.println("=="+t.year);
       System.out.println("=="+t.month);
       System.out.println("=="+t.date);
       System.out.println("=="+t.hour);
       System.out.println("=="+t.minute);
       System.out.println("=="+t.second);
       System.out.println("=========================");*/
     }
     public void startCount(){
      time t= new time();
      start_time = t;
     }
     public void stopCount(){
       time t= new time();
       stop_time = t;
     }
     public time loginTime(time start,time stop){
      time t = new time();
      //Second
        if(stop.second < start.second){
           stop.minute--;
           stop.second=+60;
           t.second = stop.second - start.second;
        }
        else
        t.second = stop.second - start.second;
       //
        if(stop.minute < start.minute){
          stop.hour--;
          stop.minute =+60;
          t.minute = stop.minute - start.minute;
        }
        else
           t.minute = stop.minute - start.minute;
        //
        if(stop.hour < start.hour){
          stop.date--;
          stop.hour=+24;
          t.hour = stop.hour - start.hour;
        }
        else
          t.hour = stop.hour - start.hour;
        //
        if(stop.date < start.date){
          stop.month--;
          stop.date=+31;
          t.date = stop.date - start.date;
        }
        else
          t.date = stop.date - start.date;
        //
        if(stop.month < start.month){
           stop.year--;
           stop.month=+12;
           t.month = stop.month - start.month;
        }
        else
         t.month = stop.month - start.month;
        //
        t.year = stop.year - start.year;


       return t;
     }

}
class time{
  int year,date,hour,minute,second;
  int month;
  public time(){
  Calendar cal = Calendar.getInstance();
   year = cal.get(Calendar.YEAR);
   month = cal.get(Calendar.MONTH)+1;
   date = cal.get(Calendar.DATE);
   hour = cal.get(Calendar.HOUR);
   minute = cal.get(Calendar.MINUTE);
   second = cal.get(Calendar.SECOND);
  }
  public time getCurrentTime(){
    time t=new time();
   return t;
  }
  public void showTime(){
    System.out.println("==================");
    System.out.println("Year ="+year);
    System.out.println("Month ="+month);
    System.out.println("Date ="+date);
    System.out.println("Hour ="+hour);
    System.out.println("Minute ="+minute);
    System.out.println("Second ="+second);
    System.out.println("===================");
  }
}


timecount.java

 

store.java

package time_counter;

/**
 * 

Title: Dial up time counter

* 

Description: Time testing pergramme

* 

Copyright: Copyright (c) 2004

* 

Company: Home

* @author N.D.I.Samantha
 * @version 1.0
 */

import java.io.*;
import java.lang.Integer;

public class store {

  public boolean storeData(time t){
   try {
         FileOutputStream out = new FileOutputStream("Data");
         PrintStream print = new PrintStream(out);

         print.println(t.year);
         print.println(t.month);
         print.println(t.date);
         print.println(t.hour);
         print.println(t.minute);
         print.println(t.second);
   }
   catch (Exception ex) {
     System.out.println("Error"+ex.toString());
   }
   return true;

  }
  public void addCurrentData(time use,time current){
    try {
          int year,date,hour,minute,second;
          int month;
          time real=use;
          FileOutputStream out = new FileOutputStream("Data");
          PrintStream print = new PrintStream(out);
          //
          if(use.second+current.second >= 60){
            real.minute++;
            real.second=(use.second+current.second)-60;
            second =real.second;
            //print.println(real.second);
          }
          else
            second=use.second + current.second;
            //print.println(use.second + current.second);
          //
          if(use.minute+current.minute >= 60){
             real.hour++;
             real.minute=(use.minute+current.minute)-60;
             minute=real.minute;
             //print.println(real.minute);
          }
          else
             minute=use.minute + current.minute;
             //print.println(use.minute + current.minute);
          //
          if(use.hour+current.hour >= 24){
             real.date++;
             real.hour=(use.hour+current.hour)-24;
             hour=real.hour;
             //print.println(real.hour);
          }
          else
            hour=use.hour + current.hour;
            //print.println(use.hour + current.hour);

          //
          if(use.date+current.date >= 31){
             real.month++;
             real.date=(use.date+current.date)-31;
             date=real.date;
             //print.println(real.date);
          }
          else
             date=use.date + current.date;
            //print.println(use.date + current.date);

          //
          if(use.month+current.month >= 12){
             real.year++;
             real.month=(use.month+current.month)-12;
             month=real.month;
             //print.println(real.month);
          }
          else
            month=use.month + current.month;
            //print.println(use.month + current.month);
          //
          print.println(use.year + current.year);
          print.println(month);
          print.println(date);
          print.println(hour);
          print.println(minute);
          print.println(second);


    }
    catch (Exception ex) {
      System.out.println("Error"+ex.toString());
    }
   return ;
  }

  public void storeBegin(){
   try {
         FileOutputStream out = new FileOutputStream("Data");
         PrintStream print = new PrintStream(out);

         print.println(0);
         print.println(0);
         print.println(0);
         print.println(0);
         print.println(0);
         print.println(0);
   }
   catch (Exception ex) {
     System.out.println("Error"+ex.toString());
   }
   return ;

  }

  public time getData(){
    time t = new time();

   try {
     FileInputStream fis=new FileInputStream("Data");
            DataInputStream dis=new DataInputStream(fis);
            t.year=Integer.parseInt(dis.readLine());
            t.month=Integer.parseInt(dis.readLine());
            t.date=Integer.parseInt(dis.readLine());
            t.hour=Integer.parseInt(dis.readLine());
            t.minute=Integer.parseInt(dis.readLine());
            t.second=Integer.parseInt(dis.readLine());

            //t.showTime();

   }
   catch (Exception ex) {
     System.out.println("Error"+ex.toString());
     return null;
   }
   return t;
  }

}

store.java

 

LogTimeMain.java

package time_counter;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/**
 * 

Title: Dial up time counter

* 

Description: Time testing pergramme

* 

Copyright: Copyright (c) 2004

* 

Company: Home

* @author N.D.I.Samantha
 * @version 1.0
 */

public class LogTimeMain extends JFrame {
  private JPanel BasePanel = new JPanel();
  private JLabel Ishara_label = new JLabel();
  private JButton Start_But = new JButton();
  private JButton Stop_But = new JButton();
  private JLabel Display_Header = new JLabel();
  private JTextArea Display = new JTextArea();
  private JButton Exit_But = new JButton();

  timecount count = new timecount();
  store sto = new store();
  time used;
  private JMenuBar jMenuBar = new JMenuBar();
  private JMenu jMenu = new JMenu();
  private JMenuItem New_Count = new JMenuItem();
  private JMenuItem Exit = new JMenuItem();
  private JLabel Email = new JLabel();
  private JLabel Website = new JLabel();
  private JLabel imglable = new JLabel();
  public LogTimeMain() {
    try {
      jbInit();
     // this.getContentPane().;
      this.setJMenuBar(jMenuBar);
      initialValusSet();
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int w = 265;
        int h = 220;
        setLocation(screenSize.width - (w+w/15), 0+ h/8 );
        setSize(w, h);
        setVisible(true);
      //this.setSize(263,179);
      //this.show();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    LogTimeMain logTimeMain = new LogTimeMain();
  }
  private void jbInit() throws Exception {
    this.getContentPane().setLayout(null);
    BasePanel.setBounds(new Rectangle(1, 2, 262, 166));
    BasePanel.setLayout(null);
    Ishara_label.setFont(new java.awt.Font("Dialog", 0, 10));
    Ishara_label.setText("Created By N.D.I. Samantha");
    Ishara_label.setBounds(new Rectangle(6, 117, 136, 17));
    Start_But.setBounds(new Rectangle(197, 12, 59, 16));
    Start_But.setFont(new java.awt.Font("Dialog", 0, 11));
    Start_But.setText("Start");
    Start_But.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Start_But_actionPerformed(e);
      }
    });
    Stop_But.setBounds(new Rectangle(197, 35, 59, 16));
    Stop_But.setFont(new java.awt.Font("Dialog", 0, 11));
    Stop_But.setText("Stop");
    Stop_But.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Stop_But_actionPerformed(e);
      }
    });
    Display_Header.setFont(new java.awt.Font("Serif", 0, 10));
    Display_Header.setText("Used time");
    Display_Header.setBounds(new Rectangle(73, 0, 54, 17));
    Display.setEditable(false);
    Display.setBounds(new Rectangle(7, 13, 173, 104));
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setResizable(false);
    this.setTitle("Time Counter");
    Exit_But.setBounds(new Rectangle(202, 105, 56, 17));
    Exit_But.setFont(new java.awt.Font("Dialog", 0, 11));
    Exit_But.setText("Exit");
    Exit_But.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Exit_But_actionPerformed(e);
      }
    });
    jMenu.setText("Counter");
    New_Count.setText("New Counter");
    New_Count.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        New_Count_actionPerformed(e);
      }
    });
    Exit.setText("Exit");
    Exit.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Exit_actionPerformed(e);
      }
    });
    Email.setFont(new java.awt.Font("Dialog", 0, 10));
    Email.setText("[email protected]");
    Email.setBounds(new Rectangle(6, 130, 150, 15));
    Website.setFont(new java.awt.Font("Dialog", 0, 11));
    Website.setText("http://www.geocities.com/isharasamantha");
    Website.setBounds(new Rectangle(26, 145, 212, 19));
    imglable.setIcon(new ImageIcon("stop.gif"));
    imglable.setBounds(new Rectangle(212, 66, 31, 29));
    this.getContentPane().add(BasePanel, null);
    BasePanel.add(Display_Header, null);
    BasePanel.add(Display, null);
    BasePanel.add(Exit_But, null);
    BasePanel.add(Start_But, null);
    BasePanel.add(Stop_But, null);
    BasePanel.add(Ishara_label, null);
    BasePanel.add(Website, null);
    BasePanel.add(Email, null);
    BasePanel.add(imglable, null);
    jMenuBar.add(jMenu);
    jMenu.add(New_Count);
    jMenu.add(Exit);
  }
  public void initialValusSet(){
   Stop_But.setEnabled(false);

   time t;// = new time();
     t=sto.getData();
     //usetime=t;
     if(t.equals(null))
       Display.setText("No still count ....");
     else{
       String dis=" Year = "+t.year+"\n Month ="+t.month+"\n" +
                  " Date = "+t.date+"\n Hour ="+t.hour+"\n" +
                  " Minute = "+t.minute+"\n Second ="+t.second+"";
       Display.setText(dis);
     }

  }

  void Exit_But_actionPerformed(ActionEvent e) {
    if(!Start_But.isEnabled()){
    used=sto.getData();
    count.stopCount();
    time cu=count.loginTime(count.start_time,count.stop_time);
    sto.addCurrentData(used,cu);
    }
    System.exit(0);
  }

  void Start_But_actionPerformed(ActionEvent e) {
    count.startCount();
    Display.setText("Time Counting .....");
    Start_But.setEnabled(false);
    Stop_But.setEnabled(true);
    imglable.setIcon(new ImageIcon("count.gif"));
  }

  void Stop_But_actionPerformed(ActionEvent e) {
    used=sto.getData();
    count.stopCount();
    time cu=count.loginTime(count.start_time,count.stop_time);
    sto.addCurrentData(used,cu);
    Stop_But.setEnabled(false);
    Start_But.setEnabled(true);
    time t=sto.getData();
    String dis=" Year = "+t.year+"\n Month ="+t.month+"\n" +
                  " Date = "+t.date+"\n Hour ="+t.hour+"\n" +
                  " Minute = "+t.minute+"\n Second ="+t.second+"";
    Display.setText(dis);
    imglable.setIcon(new ImageIcon("stop.gif"));


  }

  void Exit_actionPerformed(ActionEvent e) {
    if(!Start_But.isEnabled()){
    used=sto.getData();
    count.stopCount();
    time cu=count.loginTime(count.start_time,count.stop_time);
    sto.addCurrentData(used,cu);
    }
    System.exit(0);
  }

  void New_Count_actionPerformed(ActionEvent e) {
    int ok=JOptionPane.showConfirmDialog(this,"Are You sure","All previes data erase",JOptionPane.YES_NO_OPTION);
    switch(ok){
      case JOptionPane.OK_OPTION:
               {
                 time t;
                 sto.storeBegin();
                 t=sto.getData();
                 String dis=" Year = "+t.year+"\n Month ="+t.month+"\n" +
                            " Date = "+t.date+"\n Hour ="+t.hour+"\n" +
                            " Minute = "+t.minute+"\n Second ="+t.second+"";
                 Display.setText(dis);
               }
       case JOptionPane.CANCEL_OPTION:
          return;

    }

  }

}

LogTimeMain.java

>>Home>>

Hosted by www.Geocities.ws

1