// MsgBox3 - Displays Strings in a boxes. Non-GUI stand-alone Java // program. This version shows the creation and use of two methods. // // Written by Wayne Pollock, Tampa, FL USA, 2000 // Modified by Wayne Pollock 2005 to use Java5 Scanner class. import java.util.Scanner; class MsgBox3 { public static void main ( String [] args ) { Scanner in = new Scanner( System.in ); for ( ;; ) { System.out.print( "Enter your Message (Hit Enter to quit): " ); if ( ! in.hasNextLine() ) break; // Quit on EOF String message = in.nextLine(); if ( message.length() == 0 ) break; // Quit on empty message (or EOF) boxMsg( message ); } } public static void boxMsg ( String msg ) { drawLine( msg.length() ); // Draw the top of the box System.out.println( "\t|" + msg + "|" ); drawLine( msg.length() ); // Draw the bottom of the box } public static void drawLine ( int width ) { System.out.print( "\t+" ); for ( int i = 0; i < width; ++i ) System.out.print( "-" ); System.out.println( "+" ); } }