/*
 * Sultan Qaboos University - DCS
 * Advanced Java Programming, Spring 2011
 * Homework Assignment 1
 * Abdullah Saif AlQassabi - 57984
 *         ---------------------------
 * Simple Mathematics Learning for School Kids
 * in form of Game Playing
 *         ---------------------------
 */

package assignment1;

import java.awt.*;
import javax.swing.*;

public class MathLearning extends JFrame {
    // Variables
    private Container container;
    private JLabel scoreLabel, score;
    public  static JPanel ContainerPanel, panel1, panel2, panel3;

    public MathLearning()
    {
        super("Mathematics Learning Game");

        //Set new Font..
        Font font1 = new Font("Times New Roman", Font.PLAIN, 20),
             font2 = new Font("Cambria", Font.PLAIN, 20);

        // Create the Container
        container = getContentPane();

        // Create Panels and Set Thier Background
        ContainerPanel = new JPanel(new BorderLayout(1,1));
        panel1 = new JPanel(new FlowLayout());
        panel2 = new JPanel(new GridLayout(1,1));
        panel3 = new JPanel();

        panel1.setBackground(Color.getHSBColor(0.1f, 0.3f, 0.8f));
        panel2.setBackground(Color.getHSBColor(0.1f, 0.3f, 0.8f));

        panel1.setBorder(BorderFactory.createLineBorder(Color.WHITE));
        panel2.setBorder(BorderFactory.createLineBorder(Color.WHITE));
        
        // Label
        scoreLabel = new JLabel("Total Score: ");
        score      = new JLabel();

        scoreLabel.setFont(font2);
        scoreLabel.setForeground(Color.DARK_GRAY);

        score.setFont(font2);
        score.setForeground(Color.WHITE);

        // Add All Components to The Container
        AddCompnents();
        
        // Start The Game by Creating Threads
        startGame();
        
        // set size and location of he window
        setLocation(400, 150);
        setSize(400, 400);
        setVisible(true);
    }
    
    public void AddCompnents()
    {
        container.add(ContainerPanel);

        // Panel 1: Top Info Panel(total score, ...).
        panel1.add(scoreLabel);
        panel1.add(score);

        // Panel 2: Equation Panel(set from inside the thread).

        
        // Container Panel: adds all Panels to The Frame.
        ContainerPanel.add(panel1, BorderLayout.PAGE_START);
        ContainerPanel.add(panel2);
    }

    public void startGame()
    {
        MathThread Equation1 = new MathThread(score);
      //MathThread Equation2 = new MathThread(score);
        
        Thread eq1 = new Thread(Equation1);
        eq1.start();

        Thread eq2 = new Thread(Equation1);
        eq2.start();
        
    }

    public static void main(String[] args) {
        MathLearning application = new MathLearning();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
