Console - The file defines a class Console Objects of type...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* The file defines a class Console. Objects of type Console are windows that can be used for simple input/output exchanges with the user. Various routines are provided for reading and writing values of various types from the output. (This class exists mainly because System.out and don't work very well, at least not for beginning programming students. The file defines a class that provides an easy interface to System.out and That interface includes the same put and get routines defined in class Console, except that they are static routines that use and System.out for IO. An applet version of Consoles is also available. See the file This class is dependent on another class, ConsoleCanvas. To use a console in a program, write a class with the usual "public static void main(String[] arg)" main program. In that program, when you create an object of type Console, a console window will open. Let's say that the name of your variable is con. You would declare "Console con" and then set "con = new Console()". You can then interact with the user with statemens such as "con.putln(x)" and "x = con.getlnDouble()". When you are finished with the console, you should close it using the close() method: "con.close()". Unless the console is only for use in the main() routine, it should be declared outside the main() routine as a static variable. You won't be able to compile and run your program unless the Console and ConsoleCanvas classes are available to it. Console.class and ConsoleCanvas.class should be in the same directory as your program when you run it. When you compile your program, either the source files, and, or the compiled class files, should be in the same directory with your source code file. (If you are using a development environment such as Visual J++ or CodeWarrior, you can add the source files to your project.) Note that when a console has the input focus, it is outlined with a bright blue border. If, in addition, the console is waiting for user input, then there will be a blinking cursor. If the console is not outlined in light blue, the user has to click on it before any input will be accepted. (This is a newer version of a Console class that I originally wrote in 1996 and updated in December 1997. The newest version has been updated to make it fully compiant with Java 1.1 and to use the "realToString()" method for output of real data types.) Written by: David Eck Department of Mathematics and Computer Science Hobart and William Smith Colleges Geneva, NY 14456 Email: [email protected] WWW: July 17, 1998 */ *
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
import java.awt.*; i public class Console extends Frame { p // ***************************** Constructors ******************************* public Console() { // default constructor just provides default window title and size this("Java I/O Console",580,380); } public Console(String title) { // open window with specified title and default
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 11

Console - The file defines a class Console Objects of type...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online