It's just a basic code that prompts the user with a question (what is the password).
When the user responds with the correct answer, a dialogue should appear saying so. I have gotten to be able to enter text, but as soon as I press "OK" the application ends. I'm sure this is a noobie issue, but if someone could explain it to me I'd be much obliged.
This method has worked with just basic console, but once I try adding the JOptionPane things stop working.
- Code: Select all
import java.util.Scanner;
import javax.swing.JOptionPane;
public class TutorialProject {
static Scanner input = new Scanner(System.in);
public static void main(String[] args){
inputTest();
}
public static void inputTest(){
JOptionPane.showInputDialog("Enter the password: ");
String message = input.nextLine();
if (message.equals("password"))
JOptionPane.showMessageDialog(null, "Good job, that's the password.");
}
}
}
}