User Tools

Site Tools


it-artikel:learning-java-dowhiledemo_wargames_logindemo

Learning Java - DoWhileDemo_WarGames_LoginDemo

Just some little code demonstrating a do_while loop in java and some simple graphical userinterface prompting for input. Inspired by my favorite Hacker Movie of all times - “WarGames”.

DoWhileDemo_WarGames_Login.java
import javax.swing.JOptionPane;
 
 
public class DoWhileDemo_WarGames_Login {
	public static void main(String[] args) {
		String command;
		boolean isWrongCommand;
		int errorCounter=0;
		do{
			command = JOptionPane.showInputDialog("LOGIN: ");
			if(command.equals("Joshua")){
				isWrongCommand=false;
				JOptionPane.showMessageDialog(null, "Greetings Professor Falken!");
				if(errorCounter>0) {
					JOptionPane.showMessageDialog(null, "There has been \"" + errorCounter + "\" false login attempts since your last appearance.");
				}
			}else{
				isWrongCommand=true;
				errorCounter++;
			}
		}while(isWrongCommand);
	}
}
it-artikel/learning-java-dowhiledemo_wargames_logindemo.txt · Last modified: 2011-02-20 13:19 by mail@awerner.myhome-server.de