// [Link]
be/kQfCWkZKK8k
// [Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class GameModuleFiles
{
public static void main(String[] args)
{
JFrame frame = new JFrame("SHOWS HOW FILES COULD BE USED IN A GUI");
[Link](new BorderLayout());
CardForGameModuleFiles panel = new CardForGameModuleFiles();
[Link](panel, [Link]);
[Link](960, 600);
[Link](200, 140);
[Link](true);
[Link](JFrame.EXIT_ON_CLOSE);
}
}
class CardForGameModuleFiles extends JPanel
{
private CardLayout listOfCards;
private GameData data;
public CardForGameModuleFiles ( )
{
data = new GameData();
[Link]();
setBackground([Link]);
setBorder([Link](10, 10, 10, 10));
listOfCards = new CardLayout();
setLayout(listOfCards);
StartPanel first = new StartPanel(data, listOfCards, this);
add(first, "1");
QuestionsPanel second = new QuestionsPanel(data, listOfCards, this);
add(second, "2");
HighScoresPanel third = new HighScoresPanel(data, listOfCards, this);
add(third, "3");
}
}
class StartPanel extends JPanel implements ActionListener
{
private GameData data;
private CardLayout listOfCards;
private CardForGameModuleFiles primaryPanel;
private JTextField firstNameField, lastNameField;
public StartPanel(GameData d, CardLayout c, CardForGameModuleFiles p)
{
data = d;
listOfCards = c;
primaryPanel = p;
setBackground([Link]);
setLayout(new GridLayout(3, 1, 10, 10));
Font myFont = new Font("Tahoma", [Link], 22);
JPanel firstNamePanel = new JPanel();
[Link](Color.LIGHT_GRAY);
[Link](new FlowLayout([Link], 20, 70));
add(firstNamePanel);
JLabel firstNamePrompt = new JLabel("First Name: ");
[Link](myFont);
[Link](firstNamePrompt);
firstNameField = new JTextField(16);
[Link](new Insets(10,10,10,10));
[Link](myFont);
[Link](firstNameField);
JPanel buttonPanel = new JPanel();
[Link](Color.LIGHT_GRAY);
[Link](new FlowLayout([Link], 20, 70));
add(buttonPanel);
JButton next = new JButton("NEXT PANEL");
[Link](myFont);
[Link](this);
[Link](next);
}
public void actionPerformed(ActionEvent evt)
{
String command = [Link]();
if([Link]("NEXT PANEL"))
{
[Link](primaryPanel);
}
}
}
class QuestionsPanel extends JPanel implements ActionListener
{
private GameData data;
private CardLayout listOfCards;
private CardForGameModuleFiles primaryPanel;
private ButtonGroup group;
private JTextArea questionArea;
private JRadioButton [] answer;
private JButton submit, nextQuestion, nextPanel;
public QuestionsPanel(GameData d, CardLayout c, CardForGameModuleFiles p)
{
data = d;
listOfCards = c;
primaryPanel = p;
setBackground([Link]);
setLayout(new BorderLayout(10, 10));
Font myFont = new Font("Tahoma", [Link], 22);
answer = new JRadioButton[4];
JPanel question = new JPanel();
[Link]([Link]);
[Link]([Link](30, 30, 30, 30));
[Link](new BorderLayout());
add(question, [Link]);
questionArea = new JTextArea([Link](), 3, 30);
[Link](myFont);
[Link](true);
[Link](true);
[Link](false);
[Link](false);
[Link](questionArea, [Link]);
JPanel answers = new JPanel();
[Link]([Link]);
[Link]([Link](20, 20, 20, 20));
[Link](new GridLayout(2, 2, 20, 20));
add(answers, [Link]);
JPanel buttonPanel = new JPanel();
[Link]([Link]);
[Link](new FlowLayout([Link], 20, 30));
add(buttonPanel, [Link]);
nextPanel = new JButton("NEXT PANEL");
[Link](myFont);
[Link](this);
[Link](false);
[Link](nextPanel);
}
public void actionPerformed(ActionEvent evt)
{
String command = [Link]();
if([Link]() != null)
{
[Link](true);
}
if([Link]("SUBMIT"))
{
answer[[Link]()].setBackground([Link]);
for(int i = 0; i < [Link]; i++)
{
if(answer[i].isSelected())
{
if(i != [Link]())
{
answer[i].setBackground([Link]);
}
else
{
[Link]();
}
}
}
[Link]();
for(int i = 0; i < [Link]; i++)
{
answer[i].setEnabled(false);
}
[Link](false);
if([Link]() == 4)
{
[Link](true);
}
else
{
[Link](true);
}
}
else if([Link]("NEXT QUESTION"))
{
resetQuestion();
[Link](false);
}
else if([Link]("NEXT PANEL"))
{
[Link]();
resetQuestion();
[Link](false);
[Link](primaryPanel);
}
}
public void resetQuestion ( )
{
// [Link]();
[Link]();
[Link]([Link]());
answer[0].setText("A. " + [Link](0));
answer[1].setText("B. " + [Link](1));
answer[2].setText("C. " + [Link](2));
answer[3].setText("D. " + [Link](3));
for(int i = 0; i < [Link]; i++)
{
answer[i].setEnabled(true);
answer[i].setBackground(new Color(230, 230, 230));
}
}
}
class HighScoresPanel extends JPanel implements ActionListener
{
private GameData data;
private CardLayout listOfCards;
private CardForGameModuleFiles primaryPanel;
private JTextArea scoreInfo, highScoresArea;
public HighScoresPanel(GameData d, CardLayout c, CardForGameModuleFiles p)
{
data = d;
listOfCards = c;
primaryPanel = p;
Font myFont = new Font("Tahoma", [Link], 22);
setLayout(new BorderLayout(20, 20));
setBackground([Link]);
setBorder([Link](20, 20, 20, 20));
setFont(myFont);
JPanel centerPanel = new JPanel();
[Link](new GridLayout(1, 2, 10, 10));
add(centerPanel, [Link]);
JPanel leftSidePanel = new JPanel();
[Link]([Link](30, 30, 30,
30));
[Link](new BorderLayout());
[Link](leftSidePanel, [Link]);
scoreInfo = new JTextArea("" + [Link](), 10, 20);
[Link](myFont);
[Link](true);
[Link](true);
[Link](false);
[Link](false);
[Link](scoreInfo);
JPanel rightSidePanel = new JPanel();
[Link]([Link](30, 30, 30,
30));
[Link](new BorderLayout());
[Link](rightSidePanel, [Link]);
highScoresArea = new JTextArea("" + [Link](), 10, 20);
[Link](myFont);
[Link](true);
[Link](true);
[Link](false);
[Link](false);
[Link](new Insets(10,10,10,10));
JScrollPane scroller = new JScrollPane(highScoresArea);
[Link](scroller);
JPanel buttonPanel = new JPanel();
[Link](new FlowLayout([Link], 10, 10));
add(buttonPanel, [Link]);
JButton playAgain = new JButton("PLAY AGAIN");
[Link](myFont);
[Link](this);
[Link](playAgain);
JButton exit = new JButton("EXIT");
[Link](myFont);
[Link](this);
[Link](exit);
}
public void paintComponent(Graphics g)
{
[Link](g);
[Link]("" + [Link]());
[Link]("" + [Link]());
[Link](0);
}
public void actionPerformed(ActionEvent evt)
{
String command = [Link]();
if([Link]("PLAY AGAIN"))
{
[Link]();
[Link](primaryPanel);
}
else if([Link]("EXIT"))
{
[Link]();
[Link](0);
}
}
}
class GameData
{
private String first, last;
private String question;
private String [] answerSet;
private int correctAnswer;
private boolean [] chosenQuestions;
private int questionCount;
private int correctCount, lastGameCorrectCount;
public GameData ( )
{
first = "";
last = "";
correctCount = 0;
resetAll();
}
public void resetAll ( )
{
lastGameCorrectCount = correctCount;
answerSet = new String[4];
question = "";
for(int i = 0; i < [Link]; i++)
{
answerSet[i] = "";
}
correctAnswer = -1;
chosenQuestions = new boolean[30];
questionCount = correctCount = 0;
}
public void grabQuestionFromFile ( )
{
}
public void setName(String f, String l)
{
first = f;
last = l;
}
public String getQuestion ( )
{
return "" + questionCount + ". " + question;
}
public String getAnswer(int index)
{
return answerSet[index];
}
public int getCorrectAnswer ( )
{
return correctAnswer;
}
public int getQuestionCount ( )
{
return questionCount;
}
public int getCorrectCount ( )
{
return lastGameCorrectCount;
}
public void addOneToCorrectCount ( )
{
correctCount++;
}
public String toString ( )
{
if(lastGameCorrectCount > 2)
{
return "Congratulations, " + first + " " + last + ", you answered
" + lastGameCorrectCount +
" out of 4 of the questions correctly. Your name will be
added to the list of high scores, shown to the right. Good work!";
}
return "Good try " + first + " " + last + ", you answered " +
lastGameCorrectCount +
" out of 4 of the questions correctly. Keep working at it, and
maybe next time your name will be added to the list of high scores!";
}
public String getHighScores ( )
{
String result = "";
String fileName = "[Link]";
Scanner inFile = null;
File inputFile = new File(fileName);
try
{
inFile = new Scanner(inputFile);
}
catch(FileNotFoundException e)
{
[Link]("ERROR: Cannot open %s\n", fileName);
[Link](e);
[Link](1);
}
while([Link]())
{
String line = [Link]();
result += line + "\n";
}
return result;
}
public void saveToHighScores ( )
{
}
}