Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

What Will Be Assessed Develop, test, and execute a graphic application for simulations using Java. Java application. Given a set of events, choose...

What Will Be Assessed

Develop, test, and execute a graphic application for simulations using Java.

Java application.

Given a set of events, choose the resulting programming actions.

Understand the principles behind Java.

Understand the basic principles of object-oriented programming, including classes and inheritance.

Deliverables

.java files as requested below.

Contents

Make sure all the options are working. This means that the user choices have already had some influence on the game panel. For instance, if there is a level of difficulty option, and the user chooses "easy," the game runs slowly, and it is easy to play.

Make sure your campus panels are working with advanced functionality.

Make sure that you have more than last week for you to get any points in this assignment. 

Start the XML implementation. Choose what you are going to do with XML and begin the implementation.

import java.awt.*;

import javax.swing.*;

public class JPanelFayette extends JPanel {

JLabel jlFayette, jlGameConcept, jlGameConcept1, jlGameConcept2;

JButton jbBack;

String theme;

public JPanelFayette(String infTheme) {

super();

setLayout(null);

theme = infTheme;

jlFayette = new JLabel("FAYETTE");

jlFayette.setBounds(new Rectangle(300, 20, 220, 20));

add(jlFayette);

jlGameConcept = new JLabel("This game will be matching questions and answers.");

jlGameConcept.setBounds(new Rectangle(200, 150, 300, 20));

add(jlGameConcept);

jlGameConcept1 = new JLabel("There will be 3 questions or terms on the left side.");

jlGameConcept1.setBounds(new Rectangle(200, 200, 300, 20));

add(jlGameConcept1);

jlGameConcept2 = new JLabel("The user will match to the answer on the right side.");

jlGameConcept2.setBounds(new Rectangle(200, 250, 300, 20));

add(jlGameConcept2);

jbBack = new JButton("Back");

jbBack.setBounds(new Rectangle(270, 270, 100, 40));

add(jbBack);

}

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

Image myImage = Toolkit.getDefaultToolkit().getImage("images/background.jpg");

g.drawImage(myImage, 0, 0, this);

}

}

import java.awt.*;

import javax.swing.*;

public class JPanelWorldCampus extends JPanel {

JLabel jlWorldCampus, jlGameConceptWC, jlGameConceptWC1;

JButton jbBack;

String theme;

public JPanelWorldCampus(String infTheme) {

super();

setLayout(null);

theme = infTheme;

jlWorldCampus = new JLabel("WORLD CAMPUS");

jlWorldCampus.setBounds(new Rectangle(300, 20, 220, 20));

add(jlWorldCampus);

jlGameConceptWC = new JLabel("This game will be memory match.");

jlGameConceptWC.setBounds(new Rectangle(200, 150, 300, 20));

add(jlGameConceptWC);

jlGameConceptWC1 = new JLabel("Images will be related to the chosen theme.");

jlGameConceptWC1.setBounds(new Rectangle(200, 200, 300, 20));

add(jlGameConceptWC1);

jbBack = new JButton("Back");

jbBack.setBounds(new Rectangle(270, 270, 100, 40));

add(jbBack);

}

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

Image myImage = Toolkit.getDefaultToolkit().getImage("images/background.jpg");

g.drawImage(myImage, 0, 0, this);

}

}

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class JPanelWorthingtonScranton extends JPanel implements ActionListener {

JLabel jlWorthingtonScranton, jlInstruct1, jlInstruct2, jlInstruct3;

JButton jbBack, jbWord1, jbWord2, jbWord3, jbWord4, jbWord5, jbWord6, jbSubmit, jbCampusScore;

String theme;

JTextField input1, input2, input3, input4, input5, input6;

Integer campusScore;

public JPanelWorthingtonScranton(String infTheme) {

super();

setLayout(null);

theme = infTheme;

jlWorthingtonScranton = new JLabel("WORTHINGTON SCRANTON");

jlWorthingtonScranton.setBounds(new Rectangle(300, 20, 220, 20));

add(jlWorthingtonScranton);

campusScore = 0;

 jbCampusScore = new JButton("Score: " + campusScore);

 jbCampusScore.setBounds(new Rectangle(30, 400, 120, 20));

 add(jbCampusScore);

 input1 = new JTextField(30);

 input1.setBounds(new Rectangle(400, 130, 200, 30));

 add(input1);

 input2 = new JTextField(30);

 input2.setBounds(new Rectangle(400, 170, 200, 30));

 add(input2);

 input3 = new JTextField(30);

 input3.setBounds(new Rectangle(400, 210, 200, 30));

 add(input3);

 input4 = new JTextField(30);

 input4.setBounds(new Rectangle(400, 250, 200, 30));

 add(input4);

 input5 = new JTextField(30);

 input5.setBounds(new Rectangle(400, 290, 200, 30));

 add(input5);

 input6 = new JTextField(30);

 input6.setBounds(new Rectangle(400, 330, 200, 30));

 add(input6);

if (theme == "football") {

 jlInstruct1 = new JLabel("These football words are scrambled!");

 jlInstruct1.setBounds(new Rectangle(250,40,400,20));

 add(jlInstruct1);

 jlInstruct2 = new JLabel("Type the unscrambled word into the box.");

 jlInstruct2.setBounds(new Rectangle(250,60,400,20));

 add(jlInstruct2);

 jlInstruct3 = new JLabel("When you are done, press submit!");

 jlInstruct3.setBounds(new Rectangle(250,80,400,20));

 add(jlInstruct3);

 jbWord1 = new JButton("psas eciernrenfe");

 jbWord1.setBounds(new Rectangle(100, 130, 250, 30));

 add(jbWord1);

 jbWord2 = new JButton("nugniacnkrb");

 jbWord2.setBounds(new Rectangle(100, 170,250, 30));

 add(jbWord2);

 jbWord3 = new JButton("diew rirecvee");

 jbWord3.setBounds(new Rectangle(100, 210, 250, 30));

 add(jbWord3);

 jbWord4 = new JButton("typlena");

 jbWord4.setBounds(new Rectangle(100, 250, 250, 30));

 add(jbWord4);

 jbWord5 = new JButton("kckiffo");

 jbWord5.setBounds(new Rectangle(100, 290, 250, 30));

 add(jbWord5);

 jbWord6 = new JButton("flied loga");

 jbWord6.setBounds(new Rectangle(100, 330, 250, 30));

 add(jbWord6);

}

 if (theme == "programming") {

 jlInstruct1 = new JLabel("These programming words are scrambled!");

 jlInstruct1.setBounds(new Rectangle(250,40,400,20));

 add(jlInstruct1);

 jlInstruct2 = new JLabel("Type the unscrambled word into the box.");

 jlInstruct2.setBounds(new Rectangle(250,60,400,20));

 add(jlInstruct2);

 jlInstruct3 = new JLabel("When you are done, press submit!");

 jlInstruct3.setBounds(new Rectangle(250,80,400,20));

 add(jlInstruct3);

 jbWord1 = new JButton("baevilra");

 jbWord1.setBounds(new Rectangle(100, 130, 250, 30));

 add(jbWord1);

 jbWord2 = new JButton("gollica ropdean");

 jbWord2.setBounds(new Rectangle(100, 170,250, 30));

 add(jbWord2);

 jbWord3 = new JButton("xtsyna");

 jbWord3.setBounds(new Rectangle(100, 210, 250, 30));

 add(jbWord3);

 jbWord4 = new JButton("coitan nisrelte");

 jbWord4.setBounds(new Rectangle(100, 250, 250, 30));

 add(jbWord4);

 jbWord5 = new JButton("tapni mopnteocn");

 jbWord5.setBounds(new Rectangle(100, 290, 250, 30));

 add(jbWord5);

 jbWord6 = new JButton("geinetr");

 jbWord6.setBounds(new Rectangle(100, 330, 250, 30));

 add(jbWord6);

}

 if (theme == "math") {

 jlInstruct1 = new JLabel("These math words are scrambled!");

 jlInstruct1.setBounds(new Rectangle(250,40,400,20));

 add(jlInstruct1);

 jlInstruct2 = new JLabel("Type the unscrambled word into the box.");

 jlInstruct2.setBounds(new Rectangle(250,60,400,20));

 add(jlInstruct2);

 jlInstruct3 = new JLabel("When you are done, press submit!");

 jlInstruct3.setBounds(new Rectangle(250,80,400,20));

 add(jlInstruct3);

 jbWord1 = new JButton("mttscaahiem");

 jbWord1.setBounds(new Rectangle(100, 130, 250, 30));

 add(jbWord1);

 jbWord2 = new JButton("seisnxoserp");

 jbWord2.setBounds(new Rectangle(100, 170,250, 30));

 add(jbWord2);

 jbWord3 = new JButton("siinovdi");

 jbWord3.setBounds(new Rectangle(100, 210, 250, 30));

 add(jbWord3);

 jbWord4 = new JButton("liaconluitimpt");

 jbWord4.setBounds(new Rectangle(100, 250, 250, 30));

 add(jbWord4);

 jbWord5 = new JButton("peirm nubmer");

 jbWord5.setBounds(new Rectangle(100, 290, 250, 30));

 add(jbWord5);

 jbWord6 = new JButton("raegalb");

 jbWord6.setBounds(new Rectangle(100, 330, 250, 30));

 add(jbWord6);

}

 jbSubmit = new JButton("Submit");

 jbSubmit.setBounds(new Rectangle(270, 380, 100, 40));

 jbSubmit.addActionListener(this);

 add(jbSubmit);

jbBack = new JButton("Back");

jbBack.setBounds(new Rectangle(270, 380, 100, 40));

}

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

Image myImage = Toolkit.getDefaultToolkit().getImage("images/background.jpg");

g.drawImage(myImage, 0, 0, this);

}

   @Override

   public void actionPerformed(ActionEvent ae) {

      remove(jbSubmit);

      validate();

      repaint();

      add(jbBack);

      String text1 = input1.getText();

      if ("pass interference".equals(text1) || "variable".equals(text1) || "mathematics".equals(text1)) {

          campusScore = campusScore + 1;

          jbCampusScore.setText("Score: " + campusScore);

      }

      String text2 = input2.getText();

      if ("runningback".equals(text2) || "logical operand".equals(text2) || "expressions".equals(text2)) {

          campusScore = campusScore + 1;

          jbCampusScore.setText("Score: " + campusScore);

      }      

      String text3 = input3.getText();

      if ("wide receiver".equals(text3) || "syntax".equals(text3) || "divison".equals(text3)){

          campusScore = campusScore + 1;

          jbCampusScore.setText("Score: " + campusScore);

      }      

      String text4 = input4.getText();

      if ("penalty".equals(text4) || "action listener".equals(text4) || "multiplication".equals(text4)) {

          campusScore = campusScore + 1;

          jbCampusScore.setText("Score: " + campusScore);

      }        

      String text5 = input5.getText();

      if ("kickoff".equals(text5) || "paint component".equals(text5) || "prime number".equals(text5)) {

          campusScore = campusScore + 1;

          jbCampusScore.setText("Score: " + campusScore);

      }         

      String text6 = input6.getText();

      if ("field goal".equals(text6) || "integer".equals(text6) || "algebra".equals(text6)) {

          campusScore = campusScore + 1;

          jbCampusScore.setText("Score: " + campusScore);

      }      

   }

}

import java.awt.Color;

import java.awt.Container;

import java.awt.Graphics;

import java.awt.Image;

import java.awt.Rectangle;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import javax.swing.JPanel;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.*;

public class JPanelBrandywine extends JPanel implements ActionListener {

JLabel jlBrandywine, jlInstruct1, jlInstruct2;

JButton jbBack, jbPlayer1, jbPlayer2, jbPlayer3, jbPlayer4, jbPlayer5, jbPlayer6;

JButton jbPlayer7, jbPlayer8, jbPlayer9, jbPlayer10, jbPlayer11, jbPlayer12, currButton, jbCampusScore;

String theme;

Integer clickCount, campusScore;

public JPanelBrandywine (String infTheme) {

super();

setLayout(null);

theme = infTheme;

   JLabel jlBrandywine = new JLabel("Brandywine");

   jlBrandywine.setBounds(new Rectangle(300, 20, 220, 20));

   add(jlBrandywine);

campusScore = 0;

clickCount = 0;

 jbCampusScore = new JButton("Score: " + campusScore);

 jbCampusScore.setBounds(new Rectangle(300, 100, 120, 40));

 add(jbCampusScore);

if ("football".equals(theme)) {

 jlInstruct1 = new JLabel("Click the 4 PSU football questions.");

 jlInstruct1.setBounds(new Rectangle(250,60,400,30));

 add(jlInstruct1);

 jlInstruct2 = new JLabel("Correct answers will turn green when selected.");

 jlInstruct2.setBounds(new Rectangle(200,60,400,20));

 add(jlInstruct2);

 jbPlayer1 = new JButton("What is the nickname for Penn State's football team? Nittany Lions");

 jbPlayer1.setBounds(new Rectangle(50, 200, 250, 40));

 jbPlayer1.addActionListener(this);

 add(jbPlayer1);

 jbPlayer2 = new JButton("Who was the quarter-back of Penn State's 1986 National Championship football team? John Shaffer");

 jbPlayer2.setBounds(new Rectangle(400, 210,280, 60));

 jbPlayer2.addActionListener(this);

 add(jbPlayer2);

}

 if (theme == "programming") {

 jlInstruct1 = new JLabel("Click the 4 programming questions.");

 jlInstruct1.setBounds(new Rectangle(600,100,300,20));

 add(jlInstruct1);

 jlInstruct2 = new JLabel("Correct answers will turn green when selected.");

 jlInstruct2.setBounds(new Rectangle(500,80,300,80));

 add(jlInstruct2);

 jbPlayer1 = new JButton("Who is the creator of the JavaScript scripting language? Brendan Eich");

 jbPlayer1.setBounds(new Rectangle(30, 130, 150, 40));

 jbPlayer1.addActionListener(this);

 add(jbPlayer1);

 jbPlayer2 = new JButton("What is the most complicated language? C++");

 jbPlayer2.setBounds(new Rectangle(30, 190,150, 40));

 jbPlayer2.addActionListener(this);

 add(jbPlayer2);

}

 if (theme == "math") {

 jlInstruct1 = new JLabel("Click the 4 correct (Calculus) math problems.");

 jlInstruct1.setBounds(new Rectangle(250,40,200,20));

 add(jlInstruct1);

 jlInstruct2 = new JLabel("Correct answers will turn green when selected.");

 jlInstruct2.setBounds(new Rectangle(200,60,400,20));

 add(jlInstruct2);    

 jbPlayer1 = new JButton("d2/dx2 [ x3 ]=6x");

 jbPlayer1.setBounds(new Rectangle(30, 130, 150, 40));

 jbPlayer1.addActionListener(this);

 add(jbPlayer1);

 jbPlayer2 = new JButton("d3/dx3 [ 1 ]=0");

 jbPlayer2.setBounds(new Rectangle(30, 190,150, 40));

 jbPlayer2.addActionListener(this);

 add(jbPlayer2);

}

jbBack = new JButton("Back");

jbBack.setBounds(new Rectangle(270, 270, 100, 40));

add(jbBack);

}

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

Image myImage = Toolkit.getDefaultToolkit().getImage("images/background.jpg");

g.drawImage(myImage, 0, 0, this);

}

   @Override

   public void actionPerformed(ActionEvent event) {

   Object obj = event.getSource();

   if (clickCount >= 7) {

   }

       else {

           if (obj != jbPlayer2 && obj != jbPlayer4 && obj != jbPlayer6 && obj != jbPlayer8 && obj != jbPlayer12) {

           }

           else {

               currButton = (JButton) obj;

               currButton.setBackground(Color.GREEN);

               campusScore = campusScore + 1;

               clickCount = clickCount + 1;

               jbCampusScore.setText("Score: " + campusScore);

           }

           if (obj != jbPlayer1 && obj != jbPlayer3 && obj != jbPlayer5 && obj != jbPlayer7 && obj != jbPlayer9 && obj != jbPlayer11) {

           }

           else {

               currButton = (JButton) obj;

               currButton.setBackground(Color.RED);

               clickCount = clickCount + 1;

           }

   }

   if (clickCount != 6) {

   }

       else {

           JOptionPane.showMessageDialog(null,"Game Over");

           jbCampusScore.setText("Score: " + campusScore);

   }

   }

}

import java.awt.*;

import javax.swing.*;

public class JPanelEnd extends JPanel {

   JLabel jlEnd1, jlEnd2, jlTime;

   int time;

   JButton jbReset;

   public JPanelEnd() {

      super();

      setLayout(null);

      jlEnd1 = new JLabel("Congratulations!");

      jlEnd1.setBounds(new Rectangle(270, 160, 100, 25));

      jlEnd2 = new JLabel("You Have Successfully Visited Five Penn State Campuses");

      jlEnd2.setBounds(new Rectangle(160, 200, 400, 25));

      add(jlEnd1);

      add(jlEnd2);

      jbReset = new JButton("Play Again!");

      jbReset.setBounds(new Rectangle(270, 300, 100, 40));

      add(jbReset);

   }

   public void receivedTime(int informedTime){

      time = informedTime;

      jlTime = new JLabel("Your Time Was: " + time + " Seconds");

      jlTime.setBounds(new Rectangle(250, 245, 400, 25));

      add(jlTime);

   }

   @Override

   public void paintComponent(Graphics g) {

      super.paintComponent(g);

      Image myImage = Toolkit.getDefaultToolkit().getImage("images/background.jpg");

      g.drawImage(myImage, 0, 0, this);

   }

}

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class JPanelCampus extends JPanel implements ActionListener, KeyListener, ComponentListener {

   JButton jbUniversityPark, jbWorldCampus, jbBrandywine, jbFayette, jbErie, jbWorthingtonScranton, jbPlayer;

   JLabel jlUniversityPark, jlWorldCampus, jlBrandywine, jlFayette, jlErie, jlWorthingtonScranton;

   JLabel jlUniversityParkIcon, jlWorldCampusIcon, jlBrandywineIcon, jlFayetteIcon, jlErieIcon, jlWorthingtonScrantonIcon;

   ImageIcon imageCampusIcon, imageWorldCampus, imagePlayerProgramming, imagePlayerFootball, imagePlayerMath;

   int playerX, playerY, campusVisitCounter, totalGameTime;

   String theme;

   Timer gameTimer;

   JPanelUniversityPark jpUniversityPark;

   JPanelWorldCampus jpWorldCampus;

   JPanelBrandywine jpBrandywine;

   JPanelFayette jpFayette;

   JPanelErie jpErie;

   JPanelWorthingtonScranton jpWorthingtonScranton;

   JPanelEnd jpEnd;

   public JPanelCampus(String infTheme) {

      super();

      setLayout(null);

      setFocusable(true);

      addKeyListener(this);

      theme = infTheme;

      gameTimer = new Timer(1000, this);

      gameTimer.start();

      playerX = 280;

      playerY = 320;

      imagePlayerProgramming = new ImageIcon("images/playerProgramming.png");

      imagePlayerFootball = new ImageIcon("images/playerFootball.png");

      imagePlayerMath = new ImageIcon("images/playerMath.png");

      jbPlayer = new JButton();

      jbPlayer.setBorderPainted(false);

      jbPlayer.setContentAreaFilled(false);

      jbPlayer.setRolloverEnabled(false);

      jbPlayer.addComponentListener(this);

      jbPlayer.setBounds(new Rectangle(playerX, playerY, 50, 50));

      if (theme.equals("programming")) {

          jbPlayer.setIcon(imagePlayerProgramming);

          add(jbPlayer);

          validate();

          repaint();

      }

      if (theme.equals("football")) {

          jbPlayer.setIcon(imagePlayerFootball);

          add(jbPlayer);

          validate();

          repaint();

      }

      if (theme.equals("math")) {

          jbPlayer.setIcon(imagePlayerMath);

          add(jbPlayer);

          validate();

          repaint();

      }

      imageCampusIcon = new ImageIcon("images/campusIcon.png");

      imageWorldCampus = new ImageIcon("images/worldCampus.png");

      jbUniversityPark = new JButton();

      jbUniversityPark.setVisible(false);

      jbUniversityPark.addActionListener(this);

      jlUniversityPark = new JLabel("University Park");

      jlUniversityPark.setBounds(new Rectangle(265, 250, 100, 20));

      jlUniversityParkIcon = new JLabel();

      jlUniversityParkIcon.setBounds(new Rectangle(270, 200, 75, 50));

      jlUniversityParkIcon.setIcon(imageCampusIcon);

      jpUniversityPark = new JPanelUniversityPark(theme);

      jpUniversityPark.setBounds(new Rectangle(0, 0, 640, 480));

      jpUniversityPark.jbBack.addActionListener(this);

      add(jbUniversityPark);

      add(jlUniversityPark);

      add(jlUniversityParkIcon);

      jbWorldCampus = new JButton();

      jbWorldCampus.setVisible(false);

      jbWorldCampus.addActionListener(this);

      jlWorldCampus = new JLabel("World Campus");

      jlWorldCampus.setBounds(new Rectangle(285, 90, 100, 20));

      jlWorldCampusIcon = new JLabel();

      jlWorldCampusIcon.setBounds(new Rectangle(290, 40, 75, 50));

      jlWorldCampusIcon.setIcon(imageWorldCampus);

      jpWorldCampus = new JPanelWorldCampus(theme);

      jpWorldCampus.setBounds(new Rectangle(0, 0, 640, 480));

      jpWorldCampus.jbBack.addActionListener(this);

      add(jbWorldCampus);

      add(jlWorldCampus);

      add(jlWorldCampusIcon);

      jbBrandywine = new JButton();

      jbBrandywine.setVisible(false);

      jbBrandywine.addActionListener(this);

      jlBrandywine = new JLabel("Brandywine");

      jlBrandywine.setBounds(new Rectangle(430, 375, 100, 20));

      jlBrandywineIcon = new JLabel();

      jlBrandywineIcon.setBounds(new Rectangle(500, 360, 75, 50));

      jlBrandywineIcon.setIcon(imageCampusIcon);

      jpBrandywine = new JPanelBrandywine(theme);

      jpBrandywine.setBounds(new Rectangle(0, 0, 640, 480));

      jpBrandywine.jbBack.addActionListener(this);

      add(jbBrandywine);

      add(jlBrandywine);

      add(jlBrandywineIcon);

      jbFayette = new JButton();

      jbFayette.setVisible(false);

      jbFayette.addActionListener(this);

      jlFayette = new JLabel("Fayette");

      jlFayette.setBounds(new Rectangle(125, 365, 100, 20));

      jlFayetteIcon = new JLabel();

      jlFayetteIcon.setBounds(new Rectangle(50, 350, 75, 50));

      jlFayetteIcon.setIcon(imageCampusIcon);

      jpFayette = new JPanelFayette(theme);

      jpFayette.setBounds(new Rectangle(0, 0, 640, 480));

      jpFayette.jbBack.addActionListener(this);

      add(jbFayette);

      add(jlFayette);

      add(jlFayetteIcon);

      jbErie = new JButton();

      jbErie.setVisible(false);

      jbErie.addActionListener(this);

      jlErie = new JLabel("Erie");

      jlErie.setBounds(new Rectangle(45, 80, 100, 20));

      jlErieIcon = new JLabel();

      jlErieIcon.setBounds(new Rectangle(20, 30, 75, 50));

      jlErieIcon.setIcon(imageCampusIcon);

      jpErie = new JPanelErie(theme);

      jpErie.setBounds(new Rectangle(0, 0, 640, 480));

      jpErie.jbBack.addActionListener(this);

      add(jbErie);

      add(jlErie);

      add(jlErieIcon);

      jbWorthingtonScranton = new JButton();

      jbWorthingtonScranton.setVisible(false);

      jbWorthingtonScranton.addActionListener(this);

      jlWorthingtonScranton = new JLabel("Worthington Scranton");

      jlWorthingtonScranton.setBounds(new Rectangle(465, 185, 150, 20));

      jlWorthingtonScrantonIcon = new JLabel();

      jlWorthingtonScrantonIcon.setBounds(new Rectangle(490, 135, 75, 50));

      jlWorthingtonScrantonIcon.setIcon(imageCampusIcon);

      jpWorthingtonScranton = new JPanelWorthingtonScranton(theme);

      jpWorthingtonScranton.setBounds(new Rectangle(0, 0, 640, 480));

      jpWorthingtonScranton.jbBack.addActionListener(this);

      add(jbWorthingtonScranton);

      add(jlWorthingtonScranton);

      add(jlWorthingtonScrantonIcon);

      jpEnd = new JPanelEnd();

      jpEnd.setBounds(new Rectangle(0, 0, 640, 480));

   }

   @Override

   public void componentMoved(ComponentEvent ce) {

      Object obj = ce.getSource();

      if (obj == jbPlayer) {

          if (jbUniversityPark.isEnabled() == true) {

              if (jbPlayer.getX() > 220 && jbPlayer.getX() < 340 && jbPlayer.getY() > 155 && jbPlayer.getY() < 250) {

                  jbUniversityPark.doClick();

              }

          }

          if (jbWorldCampus.isEnabled() == true) {

              if (jbPlayer.getX() > 245 && jbPlayer.getX() < 355 && jbPlayer.getY() > -1 && jbPlayer.getY() < 90) {

                  jbWorldCampus.doClick();

              }

          }

          if (jbBrandywine.isEnabled() == true) {

              if (jbPlayer.getX() > 455 && jbPlayer.getX() < 570 && jbPlayer.getY() > 315 && jbPlayer.getY() < 415) {

                  jbBrandywine.doClick();

              }

          }

          if (jbFayette.isEnabled() == true) {

              if (jbPlayer.getX() > 0 && jbPlayer.getX() < 115 && jbPlayer.getY() > 305 && jbPlayer.getY() < 415) {

                  jbFayette.doClick();

              }

          }

          if (jbErie.isEnabled() == true) {

              if (jbPlayer.getX() > -1 && jbPlayer.getX() < 85 && jbPlayer.getY() > -1 && jbPlayer.getY() < 75) {

                  jbErie.doClick();

              }

          }

          if (jbWorthingtonScranton.isEnabled() == true) {

              if (jbPlayer.getX() > 445 && jbPlayer.getX() < 570 && jbPlayer.getY() > 90 && jbPlayer.getY() < 180) {

                  jbWorthingtonScranton.doClick();

              }

          }

      }

   }

   @Override

   public void actionPerformed(ActionEvent event) {

      Object obj = event.getSource();

      if (obj == jbUniversityPark) {

          this.removeAll();

          add(jpUniversityPark);

          validate();

          repaint();

      }

      if (obj == jbWorldCampus) {

          this.removeAll();

          add(jpWorldCampus);

          validate();

          repaint();

      }

      if (obj == jbBrandywine) {

          this.removeAll();

          add(jpBrandywine);

          validate();

          repaint();

      }

      if (obj == jbFayette) {

          this.removeAll();

          add(jpFayette);

          validate();

          repaint();

      }

      if (obj == jbErie) {

          this.removeAll();

          add(jpErie);

          validate();

          repaint();

      }

      if (obj == jbWorthingtonScranton) {

          this.removeAll();

          add(jpWorthingtonScranton);

          validate();

          repaint();

      }

      if (obj == jpUniversityPark.jbBack || obj == jpWorldCampus.jbBack || obj == jpBrandywine.jbBack || obj == jpErie.jbBack || obj == jpFayette.jbBack || obj == jpWorthingtonScranton.jbBack) {

          remove(jpUniversityPark);

          remove(jpWorldCampus);

          remove(jpBrandywine);

          remove(jpFayette);

          remove(jpErie);

          remove(jpWorthingtonScranton);

          add(jbUniversityPark);

          add(jlUniversityPark);

          add(jlUniversityParkIcon);

          add(jbWorldCampus);

          add(jlWorldCampus);

          add(jlWorldCampusIcon);

          add(jbBrandywine);

          add(jlBrandywine);

          add(jlBrandywineIcon);

          add(jbFayette);

          add(jlFayette);

          add(jlFayetteIcon);

          add(jbErie);

          add(jlErie);

          add(jlErieIcon);

          add(jbWorthingtonScranton);

          add(jlWorthingtonScranton);

          add(jlWorthingtonScrantonIcon);

          add(jbPlayer);

          campusVisitCounter++;

          validate();

          repaint();

      }

      if (obj == jpUniversityPark.jbBack) {

          jbUniversityPark.setEnabled(false);

          jlUniversityPark.setEnabled(false);

          jlUniversityParkIcon.setEnabled(false);

      }

      if (obj == jpWorldCampus.jbBack) {

          jbWorldCampus.setEnabled(false);

          jlWorldCampus.setEnabled(false);

          jlWorldCampusIcon.setEnabled(false);

      }

      if (obj == jpBrandywine.jbBack) {

          jbBrandywine.setEnabled(false);

          jlBrandywine.setEnabled(false);

          jlBrandywineIcon.setEnabled(false);

      }

      if (obj == jpFayette.jbBack) {

          jbFayette.setEnabled(false);

          jlFayette.setEnabled(false);

          jlFayetteIcon.setEnabled(false);

      }

      if (obj == jpErie.jbBack) {

          jbErie.setEnabled(false);

          jlErie.setEnabled(false);

          jlErieIcon.setEnabled(false);

      }

      if (obj == jpWorthingtonScranton.jbBack) {

          jbWorthingtonScranton.setEnabled(false);

          jlWorthingtonScranton.setEnabled(false);

          jlWorthingtonScrantonIcon.setEnabled(false);

      }

      if (obj == gameTimer){

          totalGameTime ++;

      }

      if (campusVisitCounter == 5) {

          this.removeAll();

          gameTimer.stop();

          add(jpEnd);

          jpEnd.receivedTime(totalGameTime);

          validate();

          repaint();

      }

   }

   @Override

   public void keyPressed(KeyEvent e) {

      int key = e.getKeyCode();

      if (key == KeyEvent.VK_LEFT) {

          if (playerX > 0) {

              playerX = playerX - 2;

              jbPlayer.setBounds(new Rectangle(playerX, playerY, 50, 50));

              validate();

          }

      }

      if (key == KeyEvent.VK_RIGHT) {

          if (playerX < 574) {

              playerX = playerX + 2;

              jbPlayer.setBounds(new Rectangle(playerX, playerY, 50, 50));

          }

      }

      if (key == KeyEvent.VK_UP) {

          if (playerY > 0) {

              playerY = playerY - 2;

              jbPlayer.setBounds(new Rectangle(playerX, playerY, 50, 50));

          }

      }

      if (key == KeyEvent.VK_DOWN) {

          if (playerY < 393) {

              playerY = playerY + 2;

              jbPlayer.setBounds(new Rectangle(playerX, playerY, 50, 50));

          }

      }

   }

   public void keyReleased(KeyEvent e) {

   }

   public void keyTyped(KeyEvent e) {

   }

   public void componentResized(ComponentEvent ce) {

   }

   public void componentShown(ComponentEvent ce) {

   }

   public void componentHidden(ComponentEvent ce) {

   }

   @Override

   public void paintComponent(Graphics g) {

      super.paintComponent(g);

      requestFocusInWindow();

      Image myImage = Toolkit.getDefaultToolkit().getImage("images/campusMap.png");

      g.drawImage(myImage, 0, 0, this);

   }

}

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class JPanelErie extends JPanel implements ActionListener {

JLabel jlErie, jlInstruct1, jlInstruct2;

JButton jbBack, jbPlayer1, jbPlayer2, jbPlayer3, jbPlayer4, jbPlayer5, jbPlayer6;

JButton jbPlayer7, jbPlayer8, jbPlayer9, jbPlayer10, jbPlayer11, jbPlayer12, currButton, jbCampusScore;

String theme;

Integer clickCount, campusScore;

public JPanelErie (String infTheme) {

super();

setLayout(null);

theme = infTheme;

jlErie = new JLabel("ERIE");

jlErie.setBounds(new Rectangle(300, 20, 220, 20));

add(jlErie);

campusScore = 0;

clickCount = 0;

 jbCampusScore = new JButton("Score: " + campusScore);

 jbCampusScore.setBounds(new Rectangle(300, 90, 100, 30));

 add(jbCampusScore);

if (theme == "football") {

 jlInstruct1 = new JLabel("Click the 6 PSU player names.");

 jlInstruct1.setBounds(new Rectangle(250,40,200,20));

 add(jlInstruct1);

 jlInstruct2 = new JLabel("Correct answers will turn green when selected.");

 jlInstruct2.setBounds(new Rectangle(200,60,400,20));

 add(jlInstruct2);

 jbPlayer1 = new JButton("Saquon Barkley");

 jbPlayer1.setBounds(new Rectangle(30, 130, 150, 40));

 jbPlayer1.addActionListener(this);

 add(jbPlayer1);

 jbPlayer2 = new JButton("Danny Etling");

 jbPlayer2.setBounds(new Rectangle(30, 190,150, 40));

 jbPlayer2.addActionListener(this);

 add(jbPlayer2);

 jbPlayer3 = new JButton("Akeel Lynch");

 jbPlayer3.setBounds(new Rectangle(30, 250, 150, 40));

 jbPlayer3.addActionListener(this);

 add(jbPlayer3);

 jbPlayer4 = new JButton("Myles Brennan");

 jbPlayer4.setBounds(new Rectangle(30, 310, 150, 40));

 jbPlayer4.addActionListener(this);

 add(jbPlayer4);

 jbPlayer5 = new JButton("Hayden Rettig");

 jbPlayer5.setBounds(new Rectangle(230, 130, 150, 40));

 jbPlayer5.addActionListener(this);

 add(jbPlayer5);

 jbPlayer6 = new JButton("Brendan Mahon");

 jbPlayer6.setBounds(new Rectangle(230, 190, 150, 40));

 jbPlayer6.addActionListener(this);

 add(jbPlayer6);

 jbPlayer7 = new JButton("DaeSean Hamilton");

 jbPlayer7.setBounds(new Rectangle(230, 250, 150, 40));

 jbPlayer7.addActionListener(this);

 add(jbPlayer7);

 jbPlayer8 = new JButton("Evan Washington");

 jbPlayer8.setBounds(new Rectangle(230, 310, 150, 40));

 jbPlayer8.addActionListener(this);

 add(jbPlayer8);

 jbPlayer9 = new JButton("Frank Herron");

 jbPlayer9.setBounds(new Rectangle(430, 130, 150, 40));

 jbPlayer9.addActionListener(this);

 add(jbPlayer9);

 jbPlayer10 = new JButton("Ben Kline");

 jbPlayer10.setBounds(new Rectangle(430, 190, 150, 40));

 jbPlayer10.addActionListener(this);

 add(jbPlayer10);

 jbPlayer11 = new JButton("Steph Curry");

 jbPlayer11.setBounds(new Rectangle(430, 250, 150, 40));

 jbPlayer11.addActionListener(this);

 add(jbPlayer11);

 jbPlayer12 = new JButton("Trace McSorley");

 jbPlayer12.setBounds(new Rectangle(430, 310, 150, 40));

 jbPlayer12.addActionListener(this);

 add(jbPlayer12);

}

 if (theme == "programming") {

 jlInstruct1 = new JLabel("Click the 6 programming terms.");

 jlInstruct1.setBounds(new Rectangle(250,40,200,20));

 add(jlInstruct1);

 jlInstruct2 = new JLabel("Correct answers will turn green when selected.");

 jlInstruct2.setBounds(new Rectangle(200,60,400,20));

 add(jlInstruct2);

 jbPlayer1 = new JButton("JButton");

 jbPlayer1.setBounds(new Rectangle(30, 130, 150, 40));

 jbPlayer1.addActionListener(this);

 add(jbPlayer1);

 jbPlayer2 = new JButton("addActionMover");

 jbPlayer2.setBounds(new Rectangle(30, 190,150, 40));

 jbPlayer2.addActionListener(this);

 add(jbPlayer2);

 jbPlayer3 = new JButton("setBounds");

 jbPlayer3.setBounds(new Rectangle(30, 250, 150, 40));

 jbPlayer3.addActionListener(this);

 add(jbPlayer3);

 jbPlayer4 = new JButton("introduceLimits");

 jbPlayer4.setBounds(new Rectangle(30, 310, 150, 40));

 jbPlayer4.addActionListener(this);

 add(jbPlayer4);

 jbPlayer5 = new JButton("defineBounds");

 jbPlayer5.setBounds(new Rectangle(230, 130, 150, 40));

 jbPlayer5.addActionListener(this);

 add(jbPlayer5);

 jbPlayer6 = new JButton("addActionListener");

 jbPlayer6.setBounds(new Rectangle(230, 190, 150, 40));

 jbPlayer6.addActionListener(this);

 add(jbPlayer6);

 jbPlayer7 = new JButton("Integer");

 jbPlayer7.setBounds(new Rectangle(230, 250, 150, 40));

 jbPlayer7.addActionListener(this);

 add(jbPlayer7);

 jbPlayer8 = new JButton("addSource");

 jbPlayer8.setBounds(new Rectangle(230, 310, 150, 40));

 jbPlayer8.addActionListener(this);

 add(jbPlayer8);

 jbPlayer9 = new JButton("addTime");

 jbPlayer9.setBounds(new Rectangle(430, 130, 150, 40));

 jbPlayer9.addActionListener(this);

 add(jbPlayer9);

 jbPlayer10 = new JButton("String");

 jbPlayer10.setBounds(new Rectangle(430, 190, 150, 40));

 jbPlayer10.addActionListener(this);

 add(jbPlayer10);

 jbPlayer11 = new JButton("controlListener");

 jbPlayer11.setBounds(new Rectangle(430, 250, 150, 40));

 jbPlayer11.addActionListener(this);

 add(jbPlayer11);

 jbPlayer12 = new JButton("componentListener");

 jbPlayer12.setBounds(new Rectangle(430, 310, 150, 40));

 jbPlayer12.addActionListener(this);

 add(jbPlayer12);

}

 if (theme == "math") {

 jlInstruct1 = new JLabel("Click the 6 correct math problems.");

 jlInstruct1.setBounds(new Rectangle(250,40,200,20));

 add(jlInstruct1);

 jlInstruct2 = new JLabel("Correct answers will turn green when selected.");

 jlInstruct2.setBounds(new Rectangle(200,60,400,20));

 add(jlInstruct2);    

 jbPlayer1 = new JButton("552 - 393 = 159");

 jbPlayer1.setBounds(new Rectangle(30, 130, 150, 40));

 jbPlayer1.addActionListener(this);

 add(jbPlayer1);

 jbPlayer2 = new JButton("367 + 164 = 541");

 jbPlayer2.setBounds(new Rectangle(30, 190,150, 40));

 jbPlayer2.addActionListener(this);

 add(jbPlayer2);

 jbPlayer3 = new JButton("845 - 358 = 487");

 jbPlayer3.setBounds(new Rectangle(30, 250, 150, 40));

 jbPlayer3.addActionListener(this);

 add(jbPlayer3);

 jbPlayer4 = new JButton("73 x 5 = 360");

 jbPlayer4.setBounds(new Rectangle(30, 310, 150, 40));

 jbPlayer4.addActionListener(this);

 add(jbPlayer4);

 jbPlayer5 = new JButton("9 x 5 = 40");

 jbPlayer5.setBounds(new Rectangle(230, 130, 150, 40));

 jbPlayer5.addActionListener(this);

 add(jbPlayer5);

 jbPlayer6 = new JButton("3853 + 3248 = 7101");

 jbPlayer6.setBounds(new Rectangle(230, 190, 150, 40));

 jbPlayer6.addActionListener(this);

 add(jbPlayer6);

 jbPlayer7 = new JButton("78 x 15 = 1170");

 jbPlayer7.setBounds(new Rectangle(230, 250, 150, 40));

 jbPlayer7.addActionListener(this);

 add(jbPlayer7);

 jbPlayer8 = new JButton("254 + 421 = 675");

 jbPlayer8.setBounds(new Rectangle(230, 310, 150, 40));

 jbPlayer8.addActionListener(this);

 add(jbPlayer8);

 jbPlayer9 = new JButton("165 / 5 = 34");

 jbPlayer9.setBounds(new Rectangle(430, 130, 150, 40));

 jbPlayer9.addActionListener(this);

 add(jbPlayer9);

 jbPlayer10 = new JButton("93 x 51 = 4743");

 jbPlayer10.setBounds(new Rectangle(430, 190, 150, 40));

 jbPlayer10.addActionListener(this);

 add(jbPlayer10);

 jbPlayer11 = new JButton("12 x 12 = 146");

 jbPlayer11.setBounds(new Rectangle(430, 250, 150, 40));

 jbPlayer11.addActionListener(this);

 add(jbPlayer11);

 jbPlayer12 = new JButton("6752 - 25 = 6727");

 jbPlayer12.setBounds(new Rectangle(430, 310, 150, 40));

 jbPlayer12.addActionListener(this);

 add(jbPlayer12);

}

jbBack = new JButton("Back");

jbBack.setBounds(new Rectangle(270, 380, 100, 40));

}

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

Image myImage = Toolkit.getDefaultToolkit().getImage("images/background.jpg");

g.drawImage(myImage, 0, 0, this);

}

   @Override

   public void actionPerformed(ActionEvent event) {

   Object obj = event.getSource();

   if (clickCount < 7) {

   if (obj == jbPlayer1 || obj == jbPlayer3 || obj == jbPlayer6 || obj == jbPlayer7 || obj == jbPlayer10 || obj == jbPlayer12) {

      currButton = (JButton) obj;

      currButton.setBackground(Color.GREEN);

      campusScore = campusScore + 1;

      clickCount = clickCount + 1;

      jbCampusScore.setText("Score: " + campusScore);

   }

   if (obj == jbPlayer2 || obj == jbPlayer4 || obj == jbPlayer5 || obj == jbPlayer8 || obj == jbPlayer9 || obj == jbPlayer11) {

      currButton = (JButton) obj;

      currButton.setBackground(Color.RED);

      clickCount = clickCount + 1;

   }

   }

   if (clickCount == 6) {

      JOptionPane.showMessageDialog(null,"Game Over");

      jbCampusScore.setText("Score: " + campusScore);

      add(jbBack);

      validate();

      repaint();

   }

   }

}

import java.awt.*;

import javax.swing.*;

public class JPanelIntro extends JPanel {

   JButton jbStart, jbInstructions, jbDevelopers;

   JLabel jlTitle1, jlTitle2;

   public JPanelIntro() {

      super();

      setLayout(null);

      jlTitle1 = new JLabel("Welcome To The Penn State Game!");

      jlTitle1.setBounds(new Rectangle(220, 10, 200, 40));

      add(jlTitle1);

      jlTitle2 = new JLabel("Select an Option:");

      jlTitle2.setBounds(new Rectangle(270, 40, 200, 40));

      add(jlTitle2);

      jbStart = new JButton("Start Game");

      jbStart.setBounds(new Rectangle(230, 90, 180, 80));

      jbStart.setFocusable(false);

      add(jbStart);

      jbInstructions = new JButton("Instructions");

      jbInstructions.setBounds(new Rectangle(230, 200, 180, 80));

      jbInstructions.setFocusable(false);

      add(jbInstructions);

      jbDevelopers = new JButton("Game Developers");

      jbDevelopers.setBounds(new Rectangle(230, 310, 180, 80));

      jbDevelopers.setFocusable(false);

      add(jbDevelopers);

   }

   @Override

   public void paintComponent(Graphics g) {

      super.paintComponent(g);

      Image myImage = Toolkit.getDefaultToolkit().getImage("images/background.jpg");

      g.drawImage(myImage, 0, 0, this);

   }

}

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.Border;

public class JPanelUniversityPark extends JPanel implements ActionListener {

   JLabel jlUniversityPark, jlIntro1, jlIntro2, jlIntro3, jlBox, jlEnd;

   JButton jbBegin, jbRedBall1, jbRedBall2, jbRedBall3, jbRedBall4, jbRedBall5, jbGreenBall, jbScore, jbTime, jbEnd, jbBack;

   ImageIcon imageRedBall, imageGreenBall;

   Timer movementTimer, gameTimer;

   String theme;

   int delay, score, time, greenX, greenY, red1X, red1Y, red2X, red2Y, red3X, red3Y, red4X, red4Y, red5X, red5Y;

   boolean greenTrackX, greenTrackY, red1TrackX, red1TrackY, red2TrackX, red2TrackY, red3TrackX, red3TrackY, red4TrackX, red4TrackY, red5TrackX, red5TrackY;

   Border blackline;

   public JPanelUniversityPark(String infTheme) {

      super();

      setLayout(null);

      theme = infTheme;

      imageRedBall = new ImageIcon("images/redBall.png");

      imageGreenBall = new ImageIcon("images/greenBall.png");

      jlUniversityPark = new JLabel("UNIVERSITY PARK");

      jlUniversityPark.setBounds(new Rectangle(300, 20, 220, 20));

      add(jlUniversityPark);

      jlIntro1 = new JLabel("Welcome to University Park");

      jlIntro1.setBounds(new Rectangle(240, 120, 220, 20));

      add(jlIntro1);

      jlIntro2 = new JLabel("Catch the Green Ball and Avoid the 5 Red Ones");

      jlIntro2.setBounds(new Rectangle(190, 160, 300, 20));

      add(jlIntro2);

      jlIntro3 = new JLabel();

      if (theme.equals("programming")) {

          jlIntro3.setText("As a programmer you can hack the game to move slower!");

          jlIntro3.setBounds(new Rectangle(155, 205, 400, 20));

      }

      if (theme.equals("football")) {

          jlIntro3.setText("As a football player you have faster reflexes, so one red ball is removed!");

          jlIntro3.setBounds(new Rectangle(130, 205, 450, 20));

      }

      if (theme.equals("math")) {

          jlIntro3.setText("As a math student you gain no advantage in this game!");

          jlIntro3.setBounds(new Rectangle(165, 205, 400, 20));

      }

      add(jlIntro3);

      blackline = BorderFactory.createLineBorder(Color.black);

      jlBox = new JLabel();

      jlBox.setBorder(blackline);

      jlBox.setBounds(new Rectangle(0, 110, 623, 330));

      jbBegin = new JButton("Begin!");

      jbBegin.setBounds(new Rectangle(265, 250, 100, 40));

      jbBegin.addActionListener(this);

      add(jbBegin);

      red1X = 280;

      red1Y = 200;

      red1TrackX = true;

      jbRedBall1 = new JButton();

      jbRedBall1.setFocusable(false);

      jbRedBall1.setContentAreaFilled(false);

      jbRedBall1.setRolloverEnabled(false);

      jbRedBall1.setBorderPainted(false);

      jbRedBall1.addActionListener(this);

      jbRedBall1.setBounds(new Rectangle(red1X, red1Y, 40, 40));

      jbRedBall1.setIcon(imageRedBall);

      red2X = 200;

      red2Y = 150;

      red2TrackY = true;

      jbRedBall2 = new JButton();

      jbRedBall2.setFocusable(false);

      jbRedBall2.setContentAreaFilled(false);

      jbRedBall2.setRolloverEnabled(false);

      jbRedBall2.setBorderPainted(false);

      jbRedBall2.addActionListener(this);

      jbRedBall2.setBounds(new Rectangle(red2X, red2Y, 40, 40));

      jbRedBall2.setIcon(imageRedBall);

      red3X = 390;

      red3Y = 230;

      red3TrackY = true;

      jbRedBall3 = new JButton();

      jbRedBall3.setFocusable(false);

      jbRedBall3.setContentAreaFilled(false);

      jbRedBall3.setRolloverEnabled(false);

      jbRedBall3.setBorderPainted(false);

      jbRedBall3.addActionListener(this);

      jbRedBall3.setBounds(new Rectangle(red3X, red3Y, 40, 40));

      jbRedBall3.setIcon(imageRedBall);

      red4X = 150;

      red4Y = 350;

      red4TrackX = true;

      jbRedBall4 = new JButton();

      jbRedBall4.setFocusable(false);

      jbRedBall4.setContentAreaFilled(false);

      jbRedBall4.setRolloverEnabled(false);

      jbRedBall4.setBorderPainted(false);

      jbRedBall4.addActionListener(this);

      jbRedBall4.setBounds(new Rectangle(red4X, red4Y, 40, 40));

      jbRedBall4.setIcon(imageRedBall);

      red5X = 450;

      red5Y = 350;

      red5TrackX = true;

      jbRedBall5 = new JButton();

      jbRedBall5.setFocusable(false);

      jbRedBall5.setContentAreaFilled(false);

      jbRedBall5.setRolloverEnabled(false);

      jbRedBall5.setBorderPainted(false);

      jbRedBall5.addActionListener(this);

      jbRedBall5.setBounds(new Rectangle(red5X, red5Y, 40, 40));

      jbRedBall5.setIcon(imageRedBall);

      greenX = 340;

      greenY = 200;

      jbGreenBall = new JButton();

      jbGreenBall.setFocusable(false);

      jbGreenBall.setContentAreaFilled(false);

      jbGreenBall.setRolloverEnabled(false);

      jbGreenBall.setBorderPainted(false);

      jbGreenBall.addActionListener(this);

      jbGreenBall.setBounds(new Rectangle(greenX, greenY, 40, 40));

      jbGreenBall.setIcon(imageGreenBall);

      jbScore = new JButton("Score: " + score);

      jbScore.setRolloverEnabled(false);

      jbScore.setFocusable(false);

      jbScore.setBounds(new Rectangle(200, 50, 140, 50));

      time = 30;

      jbTime = new JButton("Time: " + time);

      jbTime.setRolloverEnabled(false);

      jbTime.setFocusable(false);

      jbTime.setBounds(new Rectangle(400, 50, 140, 50));

      jbEnd = new JButton();

      jbEnd.addActionListener(this);

      jlEnd = new JLabel("Time is up. You Scored: ");

      jlEnd.setBounds(new Rectangle(250, 140, 300, 20));

      jbBack = new JButton("Back");

      jbBack.setBounds(new Rectangle(270, 270, 100, 40));

      if (theme.equals("programming")) {

          delay = 20;

      } else {

          delay = 1;

      }

      movementTimer = new Timer(delay, this);

      gameTimer = new Timer(1000, this);

   }

   @Override

   public void actionPerformed(ActionEvent event) {

      Object obj = event.getSource();

      if (obj == jbBegin) {

          remove(jlIntro1);

          remove(jlIntro2);

          remove(jlIntro3);

          remove(jbBegin);

          add(jlBox);

          add(jbScore);

          add(jbTime);

          add(jbGreenBall);

          add(jbRedBall1);

          add(jbRedBall2);

          add(jbRedBall3);

          add(jbRedBall4);

          if (theme.equals("programming") || theme.equals("math")) {

              add(jbRedBall5);

          }

          movementTimer.start();

          gameTimer.start();

          validate();

          repaint();

      }

      if (obj == movementTimer) {

          if (greenX == 0) {

              greenTrackX = true;

          }

          if (greenX == 587) {

              greenTrackX = false;

          }

          if (greenY == 107) {

              greenTrackY = true;

          }

          if (greenY == 405) {

              greenTrackY = false;

          }

          if (greenTrackX == true) {

              greenX++;

              jbGreenBall.setBounds(new Rectangle(greenX, greenY, 40, 40));

              repaint();

          }

          if (greenTrackX == false) {

              greenX--;

              jbGreenBall.setBounds(new Rectangle(greenX, greenY, 40, 40));

              repaint();

          }

          if (greenTrackY == true) {

              greenY++;

              jbGreenBall.setBounds(new Rectangle(greenX, greenY, 40, 40));

              repaint();

          }

          if (greenTrackY == false) {

              greenY--;

              jbGreenBall.setBounds(new Rectangle(greenX, greenY, 40, 40));

              repaint();

          }

          if (red1X == 0) {

              red1TrackX = true;

          }

          if (red1X == 587) {

              red1TrackX = false;

          }

          if (red1Y == 107) {

              red1TrackY = true;

          }

          if (red1Y == 405) {

              red1TrackY = false;

          }

          if (red1TrackX == true) {

              red1X++;

              jbRedBall1.setBounds(new Rectangle(red1X, red1Y, 40, 40));

              repaint();

          }

          if (red1TrackX == false) {

              red1X--;

              jbRedBall1.setBounds(new Rectangle(red1X, red1Y, 40, 40));

              repaint();

          }

          if (red1TrackY == true) {

              red1Y++;

              jbRedBall1.setBounds(new Rectangle(red1X, red1Y, 40, 40));

              repaint();

          }

          if (red1TrackY == false) {

              red1Y--;

              jbRedBall1.setBounds(new Rectangle(red1X, red1Y, 40, 40));

              repaint();

          }

          if (red2X == 0) {

              red2TrackX = true;

          }

          if (red2X == 587) {

              red2TrackX = false;

          }

          if (red2Y == 107) {

              red2TrackY = true;

          }

          if (red2Y == 405) {

              red2TrackY = false;

          }

          if (red2TrackX == true) {

              red2X++;

              jbRedBall2.setBounds(new Rectangle(red2X, red2Y, 40, 40));

              repaint();

          }

          if (red2TrackX == false) {

              red2X--;

              jbRedBall2.setBounds(new Rectangle(red2X, red2Y, 40, 40));

              repaint();

          }

          if (red2TrackY == true) {

              red2Y++;

              jbRedBall2.setBounds(new Rectangle(red2X, red2Y, 40, 40));

              repaint();

          }

          if (red2TrackY == false) {

              red2Y--;

              jbRedBall2.setBounds(new Rectangle(red2X, red2Y, 40, 40));

              repaint();

          }

          if (red3X == 0) {

              red3TrackX = true;

          }

          if (red3X == 587) {

              red3TrackX = false;

          }

          if (red3Y == 107) {

              red3TrackY = true;

          }

          if (red3Y == 405) {

              red3TrackY = false;

          }

          if (red3TrackX == true) {

              red3X++;

              jbRedBall3.setBounds(new Rectangle(red3X, red3Y, 40, 40));

              repaint();

          }

          if (red3TrackX == false) {

              red3X--;

              jbRedBall3.setBounds(new Rectangle(red3X, red3Y, 40, 40));

              repaint();

          }

          if (red3TrackY == true) {

              red3Y++;

              jbRedBall3.setBounds(new Rectangle(red3X, red3Y, 40, 40));

              repaint();

          }

          if (red3TrackY == false) {

              red3Y--;

              jbRedBall3.setBounds(new Rectangle(red3X, red3Y, 40, 40));

              repaint();

          }

          if (red4X == 0) {

              red4TrackX = true;

          }

          if (red4X == 587) {

              red4TrackX = false;

          }

          if (red4Y == 107) {

              red4TrackY = true;

          }

          if (red4Y == 405) {

              red4TrackY = false;

          }

          if (red4TrackX == true) {

              red4X++;

              jbRedBall4.setBounds(new Rectangle(red4X, red4Y, 40, 40));

              repaint();

          }

          if (red4TrackX == false) {

              red4X--;

              jbRedBall4.setBounds(new Rectangle(red4X, red4Y, 40, 40));

              repaint();

          }

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question