KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CDL > Interactive


1 /* $Id: Interactive.java,v 1.2 2004/05/20 14:23:51 bures Exp $ */
2 package SOFA.SOFAnode.Made.CDL;
3 import java.io.BufferedReader JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.InputStreamReader JavaDoc;
6
7 /** Class for ineraction with user */
8 public class Interactive {
9   static BufferedReader JavaDoc input;
10   
11   static {
12     input = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(System.in));
13   }
14
15   /** read line from std input */
16   static public String JavaDoc readLine() throws IOException JavaDoc {
17     return input.readLine();
18   }
19
20   /** write line to std output */
21   static public void writeLine(String JavaDoc line) {
22     Output.out.println(line);
23   }
24
25   /** write string to std output */
26   static public void write(String JavaDoc line) {
27     Output.out.print(line);
28   }
29
30   /** ask yes or no */
31   static public boolean askYesNo(String JavaDoc message, boolean strong, String JavaDoc strongMessage) {
32     try {
33       System.out.print(message+" (y/N): ");
34       String JavaDoc answer = input.readLine();
35       answer = answer.trim();
36       if (answer.compareTo("")==0)
37         return false;
38       if (answer.compareTo("y")==0) {
39         if (strong) {
40           System.out.print(strongMessage+" (y/N): ");
41           answer = input.readLine();
42           answer = answer.trim();
43           if (answer.compareTo("")==0)
44             return false;
45           if (answer.compareTo("y")==0)
46             return true;
47           return false;
48         }
49         return true;
50       }
51       return false;
52     } catch (IOException JavaDoc e) {
53       return false;
54     }
55   }
56 }
57
Popular Tags