Constitution Quiz
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
CoffeeScript
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package memorygame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Random;
/**
*
* @author veerasam
*/
public class MemoryGame extends JFrame {
static String files[] = {"caillou.JPG", "daddy.JPG",
"mommy.JPG", "Cat.JPG",
"rosy.JPG", "teddy.JPG"};
static JButton buttons[];
ImageIcon closedIcon;
int numButtons;
ImageIcon icons[];
Timer myTimer;
int numClicks = 0;
int oddClickIndex = 0;
int currentIndex = 0;
public MemoryGame() {
// Set the title.
setTitle("Memory Game");
// Specify an action for the close button.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a BorderLayout manager.
setLayout(new GridLayout(2, files.length));
closedIcon = new ImageIcon("closed.JPG");
numButtons = files.length * 2;
buttons = new JButton[numButtons];
icons = new ImageIcon[numButtons];
for (int i = 0, j = 0; i < files.length; i++) {
icons[j] = new ImageIcon(files[i]);
buttons[j] = new JButton("");
buttons[j].addActionListener(new ImageButtonListener());
buttons[j].setIcon(closedIcon);
add(buttons[j++]);
icons[j] = icons[j - 1];
buttons[j] = new JButton("");
buttons[j].addActionListener(new ImageButtonListener());
buttons[j].setIcon(closedIcon);
add(buttons[j++]);
}
// randomize icons array
Random gen = new Random();
for (int i = 0; i < numButtons; i++) {
int rand = gen.nextInt(numButtons);
ImageIcon temp = icons[i];
icons[i] = icons[rand];
icons[rand] = temp;
}
// Pack and display the window.
pack();
...