/home/wpollock1/public_html/Java/MsgBox3.java
// 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 Java Scanner class.
// Modified by Wayne Pollock 2014 to count Unicode characters correctly.
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 )
{
int length = msg.codePointCount( 0, msg.length() );
drawLine( length ); // Draw the top of the box
System.out.println( "\t|" + msg + "|" );
drawLine( 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( "+" );
}
}