import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class GQM
{
public static void main(String[] args)
{
JFrame jFrame;
jFrame = new JFrame();
JOptionPane.showMessageDialog(jFrame, "This is a Geography Quiz");
JOptionPane.showMessageDialog(null, "Good Luck");
char choice;
int i, choice1;
String yourChoice;
int Password;
String passString;
passString = JOptionPane.showInputDialog("Enter the Password");
// Password = passString.nextInt();
Password = Integer.parseInt(passString);
if (Password == 123)
{
JOptionPane.showMessageDialog(null, "Valid. You typed the right password. " +
"Now choose from the following menu");
JOptionPane.showMessageDialog(null, "Welcome!\nThis is a Geography Quiz\n" +
"Choose from the following Menu:");
JOptionPane.showMessageDialog(null, "1. Plate Tectonics\n2. Rivers\n3. Rocks\n4. Quit");
passString = JOptionPane.showInputDialog("Enter your choice");
choice1 = Integer.parseInt(passString);
// Convert variable from string to integer
if(choice1<1 || choice1>4)
{
JOptionPane.showMessageDialog(null, "This is an invalid choice");
}
switch(choice1)
{
case 1:
JOptionPane.showMessageDialog(null,"You are taking the Plate Tectonics Quiz");
String s = readFile("plate_tectonics.txt");
JOptionPane.showMessageDialog(null, s);
// Or you can write this into a JTextArea in your JFrame center section.
}
}
else
{
JOptionPane.showMessageDialog(null, "Invalid Password. Try Again");
}
}
private static String readFile(String path)
{
Scanner s = null;
StringBuilder sb = new StringBuilder();
String separator = " "; // or "\n"
try
{
s = new Scanner(new BufferedReader(new FileReader(path)));
s.useDelimiter(",\\s*");
while (s.hasNext())
{
sb.append(s.next(), separator);
// JOptionPane.showMessageDialog(null,s.next());
}
}
finally
{
if (s != null)
s.close();
break;
}
return sb.toString();
}
}