KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > foo > bar > Zap


1 /*****************************************************************************
2  * Copyright (C) NanoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by *
9  *****************************************************************************/

10
11 /**
12  * @author Aslak Hellesøy
13  * @version $Revision: 1570 $
14  */

15 package foo.bar;
16
17 import org.picocontainer.Startable;
18
19
20 public class Zap implements Startable {
21     private final String JavaDoc hello;
22     private String JavaDoc toString = "Not started";
23     private boolean started = false;
24
25     public Zap(String JavaDoc hello) {
26         this.hello = hello;
27     }
28
29     public void start() {
30         if(started) throw new IllegalStateException JavaDoc("Already started");
31         toString = hello + " Started";
32         System.out.println(toString() + hashCode());
33         started = true;
34     }
35
36     public void stop() {
37         if(!started) throw new IllegalStateException JavaDoc("Not started");
38         toString = hello + " Stopped";
39         System.out.println(toString() + hashCode());
40         started = false;
41     }
42
43     public String JavaDoc toString() {
44         return toString;
45     }
46 }
Popular Tags