import javax.swing.JOptionPane;

public class PrimzahlCheck {

	public static void main(String[] args) {

		while (true) {
			String eingabe = readUserMessage();
			if(eingabe == null){
				System.exit(0);
			}
			int zahl;
			zahl = Integer.parseInt(eingabe);
			String result;
			if(isPrime(zahl)){
				result = zahl+" ist eine Primzahl! :)";
			}else{
				result = zahl+" ist keine Primzahl :(";
			}
			showResult(result, "Ergebnis");
		}

	}

	public static String readUserMessage() {
		return JOptionPane.showInputDialog(null, "Geben Sie eine Zahl ein",
				"Primzahlcheck", JOptionPane.PLAIN_MESSAGE);
	}

	public static void showError(String message, String title) {
		JOptionPane.showMessageDialog(null, message, title,
				JOptionPane.WARNING_MESSAGE);
	}
	
	public static void showResult(String message, String title){
		JOptionPane.showMessageDialog(null, message, title, JOptionPane.INFORMATION_MESSAGE);
	}
	
	private static boolean isPrime (int n){
		if(n < 2){
			return false;
		}
		boolean isPrime = true;
		for(int i = 2; i*i <= n; i++){
			if(n % i == 0){
				isPrime = false;
			}
		}
		return isPrime;
	}

}