Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class AssignmentMethods{
- //first screen to be seen, asks user if they would like to open tutorial window
- public static void introScreen(){ //Main Programmer: Amarnath Parthiban
- JPanel introScreen = new JPanel();
- introScreen.setLayout(null);
- JFrame introFrame = new JFrame("Welcome");
- introFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- introFrame.add(introScreen);
- //text to be displayed on screen
- JLabel introTitle = new JLabel("So you think you're Canadian, eh?");
- introTitle.setFont(new Font("Calibri", Font.PLAIN, 20));
- introTitle.setBounds(5, 0, 500, 25);
- JLabel introText1 = new JLabel("Welcome to the CIA Canadian trivia quiz.");
- introText1.setFont(new Font("Calibri", Font.PLAIN, 16));
- introText1.setBounds(15, 25, 500, 25);
- JLabel introText2 = new JLabel("Would you like to take the tutorial?");
- introText2.setFont(new Font("Calibri", Font.PLAIN, 16));
- introText2.setBounds(25, 50, 500, 25);
- //buttons for user input
- JButton yesTutorial = new JButton("YES");
- yesTutorial.setFont(new Font("Calibri", Font.PLAIN, 16));
- yesTutorial.setBounds(55, 75, 70, 30);
- JButton noTutorial = new JButton("NO");
- noTutorial.setFont(new Font("Calibri", Font.PLAIN, 16));
- noTutorial.setBounds(165, 75, 70, 30);
- introScreen.add(introTitle);
- introScreen.add(introText1);
- introScreen.add(introText2);
- introScreen.add(yesTutorial);
- introScreen.add(noTutorial);
- introFrame.setSize(310,160);
- introFrame.setVisible(true);
- yesTutorial.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- //removes first window and opens the tutorial window
- introFrame.dispose();
- tutorial();
- }
- });
- noTutorial.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- //removes first window and opens main quiz window
- introFrame.dispose();
- quiz();
- }
- });
- }
- //static panel and frame to allow only one instance of the window to be open
- static JPanel mainQuiz = new JPanel();
- static JFrame mainFrame = new JFrame("CAI Quiz");
- static CardLayout card1 = new CardLayout();
- //used to determine if the main quiz screen is open, defaulted to false for safety
- static boolean quizState = false;
- public static void quiz(){ //Main Programmer: Amarnath Parthiban
- mainQuiz.setLayout(card1);
- mainFrame.add(mainQuiz);
- JPanel quiz = new JPanel();
- //allows use of (x,y) positions on JPanel
- quiz.setLayout(null);
- //changes the state to inform that main quiz is open and other windows can be closed without ending the program
- quizState = true;
- mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- mainQuiz.add(quiz, "a");
- //title
- JLabel mainTitle = new JLabel("CAI CANADIAN QUIZ");
- mainTitle.setFont(new Font("Calibri", Font.PLAIN, 75));
- mainTitle.setBounds(190, 25, 700, 60);
- //buttons for each question type and level including a random and tutorial button
- JButton MCLevel1 = new JButton("Multiple Choice Level 1");
- MCLevel1.setFont(new Font("Calibri", Font.PLAIN, 25));
- MCLevel1.setBounds(150, 200, 300, 100);
- JButton MCLevel2 = new JButton("Multiple Choice Level 2");
- MCLevel2.setFont(new Font("Calibri", Font.PLAIN, 25));
- MCLevel2.setBounds(150, 350, 300, 100);
- JButton MCLevel3 = new JButton("Multiple Choice Level 3");
- MCLevel3.setFont(new Font("Calibri", Font.PLAIN, 25));
- MCLevel3.setBounds(150, 500, 300, 100);
- JButton FIBLevel1 = new JButton("Fill in The Blank Level 1");
- FIBLevel1.setFont(new Font("Calibri", Font.PLAIN, 25));
- FIBLevel1.setBounds(550, 200, 300, 100);
- JButton FIBLevel2 = new JButton("Fill in The Blank Level 2");
- FIBLevel2.setFont(new Font("Calibri", Font.PLAIN, 25));
- FIBLevel2.setBounds(550, 350, 300, 100);
- JButton FIBLevel3 = new JButton("Fill in The Blank Level 3");
- FIBLevel3.setFont(new Font("Calibri", Font.PLAIN, 25));
- FIBLevel3.setBounds(550, 500, 300, 100);
- JButton random = new JButton("Random");
- random.setFont(new Font("Calibri", Font.PLAIN, 25));
- random.setBounds(350, 650, 300, 100);
- JButton tutorial = new JButton("Tutorial");
- tutorial.setFont(new Font("Calibri", Font.PLAIN, 20));
- tutorial.setBounds(10, 650, 100, 100);
- quiz.add(mainTitle);
- quiz.add(MCLevel1);
- quiz.add(MCLevel2);
- quiz.add(MCLevel3);
- quiz.add(FIBLevel1);
- quiz.add(FIBLevel2);
- quiz.add(FIBLevel3);
- quiz.add(random);
- quiz.add(tutorial);
- mainFrame.setSize(1000,800);
- mainFrame.setVisible(true);
- card1.show(mainQuiz, "a");
- MCLevel1.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- MCLevel1();
- }
- });
- MCLevel2.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- MCLevel2();
- }
- });
- MCLevel3.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- MCLevel3();
- }
- });
- FIBLevel1.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- FIBLevel1();
- }
- });
- FIBLevel2.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- FIBLevel2();
- }
- });
- FIBLevel3.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- FIBLevel3();
- }
- });
- tutorial.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- //allows user to open tutorial when needed
- tutorial();
- }
- });
- }
- public static void MCLevel1(){ //Main Programmer: Amarnath Parthiban
- JPanel MC1 = new JPanel();
- MC1.setLayout(null);
- mainQuiz.add(MC1, "b");
- JLabel MC1Title = new JLabel("Score");
- MC1Title.setFont(new Font("Calibri", Font.PLAIN, 75));
- MC1Title.setBounds(380, 25, 700, 120);
- JLabel scoreDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- scoreDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- scoreDescription.setBounds(150, 50, 700, 500);
- JButton scoreBack = new JButton("Return");
- scoreBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- scoreBack.setBounds(350, 600, 300, 100);
- MC1.add(MC1Title);
- MC1.add(scoreDescription);
- MC1.add(scoreBack);
- card1.show(mainQuiz, "b");
- scoreBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- quiz();
- }
- });
- }
- public static void MCLevel2(){ //Main Programmer: Amarnath Parthiban
- JPanel MC2 = new JPanel();
- MC2.setLayout(null);
- mainQuiz.add(MC2, "c");
- JLabel MC1Title = new JLabel("Score");
- MC1Title.setFont(new Font("Calibri", Font.PLAIN, 75));
- MC1Title.setBounds(380, 25, 700, 120);
- JLabel scoreDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- scoreDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- scoreDescription.setBounds(150, 50, 700, 500);
- JButton scoreBack = new JButton("Return");
- scoreBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- scoreBack.setBounds(350, 600, 300, 100);
- MC2.add(MC1Title);
- MC2.add(scoreDescription);
- MC2.add(scoreBack);
- card1.show(mainQuiz, "c");
- scoreBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- quiz();
- }
- });
- }
- public static void MCLevel3(){ //Main Programmer: Amarnath Parthiban
- JPanel MC3 = new JPanel();
- MC3.setLayout(null);
- mainQuiz.add(MC3, "d");
- JLabel MC1Title = new JLabel("Score");
- MC1Title.setFont(new Font("Calibri", Font.PLAIN, 75));
- MC1Title.setBounds(380, 25, 700, 120);
- JLabel scoreDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- scoreDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- scoreDescription.setBounds(150, 50, 700, 500);
- JButton scoreBack = new JButton("Return");
- scoreBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- scoreBack.setBounds(350, 600, 300, 100);
- MC3.add(MC1Title);
- MC3.add(scoreDescription);
- MC3.add(scoreBack);
- card1.show(mainQuiz, "d");
- scoreBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- quiz();
- }
- });
- }
- public static void FIBLevel1(){ //Main Programmer: Amarnath Parthiban
- JPanel FIB1 = new JPanel();
- FIB1.setLayout(null);
- mainQuiz.add(FIB1, "e");
- JLabel MC1Title = new JLabel("Score");
- MC1Title.setFont(new Font("Calibri", Font.PLAIN, 75));
- MC1Title.setBounds(380, 25, 700, 120);
- JLabel scoreDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- scoreDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- scoreDescription.setBounds(150, 50, 700, 500);
- JButton scoreBack = new JButton("Return");
- scoreBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- scoreBack.setBounds(350, 600, 300, 100);
- FIB1.add(MC1Title);
- FIB1.add(scoreDescription);
- FIB1.add(scoreBack);
- card1.show(mainQuiz, "e");
- scoreBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- quiz();
- }
- });
- }
- public static void FIBLevel2(){ //Main Programmer: Amarnath Parthiban
- JPanel FIB2 = new JPanel();
- FIB2.setLayout(null);
- mainQuiz.add(FIB2, "f");
- JLabel MC1Title = new JLabel("Score");
- MC1Title.setFont(new Font("Calibri", Font.PLAIN, 75));
- MC1Title.setBounds(380, 25, 700, 120);
- JLabel scoreDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- scoreDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- scoreDescription.setBounds(150, 50, 700, 500);
- JButton scoreBack = new JButton("Return");
- scoreBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- scoreBack.setBounds(350, 600, 300, 100);
- FIB2.add(MC1Title);
- FIB2.add(scoreDescription);
- FIB2.add(scoreBack);
- card1.show(mainQuiz, "f");
- scoreBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- quiz();
- }
- });
- }
- public static void FIBLevel3(){ //Main Programmer: Amarnath Parthiban
- JPanel FIB3 = new JPanel();
- FIB3.setLayout(null);
- mainQuiz.add(FIB3, "g");
- JLabel MC1Title = new JLabel("Score");
- MC1Title.setFont(new Font("Calibri", Font.PLAIN, 75));
- MC1Title.setBounds(380, 25, 700, 120);
- JLabel scoreDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- scoreDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- scoreDescription.setBounds(150, 50, 700, 500);
- JButton scoreBack = new JButton("Return");
- scoreBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- scoreBack.setBounds(350, 600, 300, 100);
- FIB3.add(MC1Title);
- FIB3.add(scoreDescription);
- FIB3.add(scoreBack);
- card1.show(mainQuiz, "g");
- scoreBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- quiz();
- }
- });
- }
- //static panel and frame to allow only one instance of the window to be open
- static JPanel mainTutorial = new JPanel();
- static JFrame tutorialFrame = new JFrame("Tutorial");
- //allows for multiple JPanels on one JFrame
- static CardLayout card2 = new CardLayout();
- public static void tutorial(){ //Main Programmer: Amarnath Parthiban
- mainTutorial.setLayout(card2);
- tutorialFrame.add(mainTutorial);
- //additional panel to set on top and interchange between other panels
- JPanel tutorial = new JPanel();
- tutorial.setLayout(null);
- mainTutorial.add(tutorial, "one");
- //determine if the tutorial window needs to stop the program or not
- if (quizState == true)
- tutorialFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- else
- tutorialFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //title for the panel
- JLabel tutorialTitle = new JLabel("Tutorial");
- tutorialTitle.setFont(new Font("Calibri", Font.PLAIN, 75));
- tutorialTitle.setBounds(380, 25, 700, 60);
- //buttons for each topic, including a quiz button
- JButton score = new JButton("Score");
- score.setFont(new Font("Calibri", Font.PLAIN, 32));
- score.setBounds(150, 200, 300, 100);
- JButton level = new JButton("Level");
- level.setFont(new Font("Calibri", Font.PLAIN, 32));
- level.setBounds(150, 400, 300, 100);
- JButton type = new JButton("Type");
- type.setFont(new Font("Calibri", Font.PLAIN, 32));
- type.setBounds(550, 200, 300, 100);
- JButton answering = new JButton("Answering");
- answering.setFont(new Font("Calibri", Font.PLAIN, 32));
- answering.setBounds(550, 400, 300, 100);
- JButton main = new JButton("QUIZ SCREEN");
- main.setFont(new Font("Calibri", Font.PLAIN, 32));
- main.setBounds(350, 600, 300, 100);
- tutorial.add(tutorialTitle);
- tutorial.add(score);
- tutorial.add(level);
- tutorial.add(type);
- tutorial.add(answering);
- tutorial.add(main);
- tutorialFrame.setSize(1000,800);
- tutorialFrame.setVisible(true);
- //displays the home tutorial panel
- card2.show(mainTutorial, "one");
- //calling methods for each of the topics depending on button pushed
- score.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- score();
- }
- });
- level.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- level();
- }
- });
- type.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- type();
- }
- });
- answering.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- answering();
- }
- });
- main.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- //open the quiz window, make the tutoral window disposible without ending the program
- tutorialFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- quiz();
- }
- });
- }
- //START: methods used by the tutorial screen exclusively
- //each method contains a title, a brief description and a button to return to the main tutorial screen
- public static void score(){ //Main Programmer: Amarnath Parthiban
- JPanel scoreTutorial = new JPanel();
- scoreTutorial.setLayout(null);
- mainTutorial.add(scoreTutorial, "two");
- JLabel scoreTitle = new JLabel("Score");
- scoreTitle.setFont(new Font("Calibri", Font.PLAIN, 75));
- scoreTitle.setBounds(380, 25, 700, 120);
- JLabel scoreDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- scoreDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- scoreDescription.setBounds(150, 50, 700, 500);
- JButton scoreBack = new JButton("Return");
- scoreBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- scoreBack.setBounds(350, 600, 300, 100);
- scoreTutorial.add(scoreTitle);
- scoreTutorial.add(scoreDescription);
- scoreTutorial.add(scoreBack);
- card2.show(mainTutorial, "two");
- scoreBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- tutorial();
- }
- });
- }
- public static void level(){ //Main Programmer: Amarnath Parthiban
- JPanel levelTutorial = new JPanel();
- levelTutorial.setLayout(null);
- mainTutorial.add(levelTutorial, "three");
- JLabel levelTitle = new JLabel("Level");
- levelTitle.setFont(new Font("Calibri", Font.PLAIN, 75));
- levelTitle.setBounds(380, 25, 700, 120);
- JLabel levelDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- levelDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- levelDescription.setBounds(150, 50, 700, 500);
- JButton levelBack = new JButton("Return");
- levelBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- levelBack.setBounds(350, 600, 300, 100);
- levelTutorial.add(levelTitle);
- levelTutorial.add(levelDescription);
- levelTutorial.add(levelBack);
- card2.show(mainTutorial, "three");
- levelBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- tutorial();
- }
- });
- }
- public static void type(){ //Main Programmer: Amarnath Parthiban
- JPanel typeTutorial = new JPanel();
- typeTutorial.setLayout(null);
- mainTutorial.add(typeTutorial, "four");
- JLabel typeTitle = new JLabel("Type");
- typeTitle.setFont(new Font("Calibri", Font.PLAIN, 75));
- typeTitle.setBounds(380, 25, 700, 120);
- JLabel typeDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- typeDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- typeDescription.setBounds(150, 50, 700, 500);
- JButton typeBack = new JButton("Return");
- typeBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- typeBack.setBounds(350, 600, 300, 100);
- typeTutorial.add(typeTitle);
- typeTutorial.add(typeDescription);
- typeTutorial.add(typeBack);
- card2.show(mainTutorial, "four");
- typeBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- tutorial();
- }
- });
- }
- public static void answering(){ //Main Programmer: Amarnath Parthiban
- JPanel answeringTutorial = new JPanel();
- answeringTutorial.setLayout(null);
- mainTutorial.add(answeringTutorial, "five");
- JLabel answeringTitle = new JLabel("Answering");
- answeringTitle.setFont(new Font("Calibri", Font.PLAIN, 75));
- answeringTitle.setBounds(320, 25, 700, 120);
- JLabel answeringDescription = new JLabel("<html>Your score, displayed as a percentage, will directly repersent the amount of question you answerd correnctl compared to the total amount of questions you've answered."
- + " On the main menu your score will be displayed once as your overall score."
- + " When in a session your total score as well as your session score will be visible."
- + " These scores will automaticly updated as you continue on with your session."
- + " If you choose to end session prematurely (before you have answered all the questions) your session pregress will not be saved and will not be added to your total score. </html>");
- answeringDescription.setFont(new Font("Calibri", Font.PLAIN, 25));
- answeringDescription.setBounds(150, 50, 700, 500);
- JButton answeringBack = new JButton("Return");
- answeringBack.setFont(new Font("Calibri", Font.PLAIN, 32));
- answeringBack.setBounds(350, 600, 300, 100);
- answeringTutorial.add(answeringTitle);
- answeringTutorial.add(answeringDescription);
- answeringTutorial.add(answeringBack);
- card2.show(mainTutorial, "five");
- answeringBack.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- tutorial();
- }
- });
- }
- //END: methods used by the tutorial screen exclusively
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement