To download code/application click the following link 99applications.com/java_programs and you can also find many c and c plus plus common programs in C & C++ section
Visit http://freesourcecode.blogspot.com for Thambola, Housie, Love Calculator, Friendship Calculator, FLAMES, Animations, Digital Number, Sudoku.java - Java Programmes.
/***********************************************************/
Program to Print a File in Type Writing Style
- Krishnakanth Soni
sonikrishnakanth@gmail.com
/***********************************************************/
Output Screen
Program to Print a File in Type Writing Style
- Krishnakanth Soni
sonikrishnakanth@gmail.com
/***********************************************************/
Output Screen
One Charector of file is printed for the specified speed..... So output may be some animation type when you execute.....
import java.io.*;public class TypeWriter
{
long typingSpeed; //in nano seconds, letter per speed
File fileToType;
public TypeWriter(){
typingSpeed = 100;
fileToType = null;
}
public void setTypingSpeed( long typingSpeed ){
this.typingSpeed = typingSpeed;
}
public void setFileToType( String fileToType ){
if( fileToType.endsWith( ".txt" ) ){
this.fileToType = new File( fileToType );
if( ! this.fileToType.exists() ){
type( "-----------\nFile Not Found.....\n\n" );
System.exit( 0 );
}
}else{
type( "-----------\nFile is Not a Text Document.......\n\n" );
}
if( this.fileToType == null ){
type( "-----------\nFile Not Set.....\n\n" );
System.exit( 0 );
}
}
public void type( String line ){
for( int i=0; i < line.length(); i++ ){
System.out.print(line.charAt(i) + "" );
try{
Thread.sleep( typingSpeed );
}catch(Exception e){}
}
}
public void startTyping(){
if( fileToType == null ){
type( "-----------\nFile Not Set.....\n\n" );
System.exit( 0 );
}
try{
System.out.println( "\n\nFile Typing Started....\n\n" );
BufferedReader br = new BufferedReader( new FileReader( fileToType ) );
String str = "";
while( (str = br.readLine() ) != null ){
type( str );
}
}catch(Exception e){}
}
public static void main( String args[] ){
TypeWriter tw = new TypeWriter();
tw.setTypingSpeed( 50 );
tw.setFileToType( args[0] );
tw.startTyping();
}
}
Home
No comments:
Post a Comment