MsgBox.java

Download MsgBox.java

 1: // Displays an input String in a box.  Non-GUI stand-alone
 2: // Java program.
 3: //
 4: // Written by Wayne Pollock, Tampa, FL USA, 2000
 5: // Modified by Wayne Pollock, 2005, to use Java5 Scanner class.
 6: 
 7: import java.util.Scanner;
 8: 
 9: class MsgBox
10: {
11:    public static void main ( String [] args )
12:    {
13:       Scanner in = new Scanner( System.in );
14: 
15:       System.out.print( "Enter your Message: " );
16: 
17:       if ( ! in.hasNextLine() )
18:          return;  // All done on EOF, so just exit.
19: 
20:       String message = in.nextLine();
21: 
22:       int msgLength = message.length();
23: 
24:       // Draw the top of the box:
25:       System.out.print( "\t+" );
26:       for ( int i = 0; i < msgLength; ++i )
27:          System.out.print( "-" );
28:       System.out.println( "+" );
29: 
30:       // Print the message:
31:       System.out.println( "\t|" + message + "|" );
32: 
33:       // Draw the bottom of the box:
34:       System.out.print( "\t+" );
35:       for ( int i = 0; i < msgLength; ++i )
36:          System.out.print( "-" );
37:       System.out.println( "+" );
38:    }
39: }