KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > wrd > Counter


1 package org.enhydra.shark.wrd;
2
3 import java.io.Serializable JavaDoc;
4
5 public class Counter implements Serializable JavaDoc, Cloneable JavaDoc {
6
7    private int no;
8
9    public void increment () {
10       no++;
11    }
12
13    public void decrement () {
14       no--;
15    }
16
17    public int value () {
18       return no;
19    }
20
21    public void reset () {
22       no=0;
23    }
24
25    public String JavaDoc toString () {
26       return "I'm counter and my value is "+no;
27    }
28
29    public Object JavaDoc clone () {
30       try {
31          return super.clone();
32       } catch (Exception JavaDoc ex) {
33          return null;
34       }
35    }
36
37    public boolean equals (Object JavaDoc obj) {
38       if (!(obj instanceof Counter)) return false;
39       Counter cnt=(Counter)obj;
40       if (cnt.no==no) {
41          return true;
42       } else {
43          return false;
44       }
45    }
46 }
47
Popular Tags