001 /* 002 * cs101 ServerDialog 003 * $Id: ServerDialog.java,v 1.1.1.1 2002/06/05 21:56:32 root Exp $ 004 * 005 * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group. 006 * For more information, see <a href="http://www.ai.mit.edu/projects/cs101/">the 007 * CS101 homepage</a> or email <las@ai.mit.edu>. 008 * 009 * Copyright (C) 1996 Massachusetts Institute of Technology. 010 * Please do not redistribute without obtaining permission. 011 */ 012 013 package cs101.awt; 014 015 /** 016 * Manages a top level query dialog box to get port connection information. 017 * To display the dialog box, use ask(); to extract the port number, use 018 * getPort().<p> 019 * 020 * Relies heavily on QueryDialog. 021 * 022 * <P>Copyright (c) 1998 Massacuhsetts Institute of Technology 023 * 024 * @author Todd C. Parnell, tparnell@ai.mit.edu 025 * @author Nathan Williams <nathanw@mit.edu> 026 * @author Lynn Andrea Stein <las@ai.mit.edu> 027 * @version $Id: ServerDialog.java,v 1.1.1.1 2002/06/05 21:56:32 root Exp $ 028 * 029 * @see cs101.awt.QueryDialog 030 * @see #ask 031 * @see #getPort 032 */ 033 public class ServerDialog { 034 035 protected QueryDialog qd; 036 protected String[] answers, 037 questions; 038 /** 039 * Creates the dialog information. 040 * To show the dialog, call ask(). 041 * To retrieve information, use int getPort(). 042 */ 043 public ServerDialog() { 044 this.questions = new String[1]; 045 this.questions[0] = "Port"; 046 this.answers = new String[1]; 047 this.answers[0] = "4321"; 048 this.qd = new QueryDialog("Please enter the port to listen on.", 049 this.questions, 050 this.answers); 051 } 052 053 /** 054 * Actually display the query dialog and get the answers from the user. 055 * 056 * @see #getPort() 057 */ 058 public synchronized void ask() { 059 this.answers = this.qd.ask(); 060 } 061 062 /** 063 * Return the port number from the user. Not guaranteed to be sensible 064 * if ask hasn't aready been called. 065 * 066 * @see #ask() 067 */ 068 public synchronized int getPort() { 069 try { 070 return Integer.parseInt( this.answers[0] ); 071 } catch ( NumberFormatException e ) { 072 throw new RuntimeException("Bad port number '"+answers[0]+"'"); 073 } 074 } 075 076 } 077 078 079 /* 080 * $Log: ServerDialog.java,v $ 081 * Revision 1.1.1.1 2002/06/05 21:56:32 root 082 * CS101 comes to Olin finally. 083 * 084 * Revision 1.5 1998/07/24 17:06:31 tparnell 085 * Placate new javadoc behavior 086 * 087 * Revision 1.4 1998/07/22 18:18:41 tparnell 088 * migration from cs101.util to cs101.* 089 * 090 * Revision 1.3 1998/07/21 20:19:17 tparnell 091 * javadoc bugfix 092 * 093 * Revision 1.2 1998/06/03 19:52:01 tparnell 094 * update from Java 1.0 to 1.1 095 * 096 * Revision 1.1 1998/03/13 22:18:21 tparnell 097 * Import from server crash. I think the src and class files match up. 098 * 099 * Revision 1.1 1996/11/18 17:25:06 las 100 * Added revised SharedWhiteboard support classes. These versions of 101 * Client and Server supercede the previous ones and are not directly 102 * backwards compatible. In particular, Server is an instantiable class 103 * rather than a primarily static one (use RunServer to run it), and 104 * Client uses StringHandler rather than subclassing to specialize it. 105 * Line.java just picked up some obscure documentation along the way. 106 * Otherwise, classes are direct imports from SharedWhiteboard. 107 * 108 * Revision 1.4 1996/11/17 22:28:17 las 109 * Everything compiles (now). Client, Server, ClientDialog, ServerDialog, 110 * StringHandler, and RunServer need to be moved to cs101.util. But 111 * first, to test.... 112 * 113 * Revision 1.3 1996/11/17 21:26:54 las 114 * Client, ClientDialog writen, not yet tested. 115 * 116 */ 117