children learning system report

52
Faculty of Information Science and Technology Multimedia University TCP 1311 OBJECT-ORIENTED PROGRAMMING Trimester 1, Session 2009/2010 LECTURER: MR. MD. SHOHEL SAYEED TUTORIAL SECTION: TMG 06 D PROJECT TITLE: Children learning system STUDENT NAME: MOHGAMBIHAI A/P MOGANALINGAM ID: 1081100406

Upload: hunterxv

Post on 04-Mar-2015

24 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Children Learning System Report

Faculty of Information Science and TechnologyMultimedia University

TCP 1311 OBJECT-ORIENTED PROGRAMMINGTrimester 1, Session 2009/2010

LECTURER: MR. MD. SHOHEL SAYEED

TUTORIAL SECTION: TMG 06 D

PROJECT TITLE: Children learning system

STUDENT NAME: MOHGAMBIHAI A/P MOGANALINGAM

ID: 1081100406

Page 2: Children Learning System Report

TCP 1311

No Content Page

1. System Introduction 3

2.Assumptions

4

3.

UML Diagrams

A: Use Case DiagramB: Class DiagramC: Sequence DiagramD: Collaboration DiagramE: State Diagram

5

4.

Appendix

A: Source CodeB: Sample Interface ScreenC: Sample Input/Output Screens

9

5. Appreciation 42

2

Page 3: Children Learning System Report

TCP 1311

(I) System Introduction

The Children Learning System is a system that gives children of ages 4 to 6 on how to use an interactive application.

This interactive system will enable children see what happens when they rollover their mouse over the buttons in the menus and in the options. Moreover, clicking an option to select the answer and then summiting the answer for checking, is in real time. Result after solving three questions will be displayed for each category.

The system deals with attractive images for children to match with their corresponding names. Matching images which include animals, fruits, and colors.

The system allows simple mathematical operation for children to fill in the blanks for the correct answer. The numbers menu is designed for counting, addition/subtraction and multiplication/division.

The frame uses java Swing’s UI Manager to manage defaults and extensively implements java GUI. The compiled program is to be run using command prompt.

The system has robust coding which can include additional features such as background and effects sound and welcoming front page that has not been implemented. The system contains no errors as all exceptions are handled carefully.

Children Learning System

3

Page 4: Children Learning System Report

TCP 1311

(II) Assumptions

The Children Learning system assumes that the children should explore the menus and it with the activities on their own as this would promote their self-learning of interactive system.

Since the system aims to provide basic knowledge on interactive systems, there are simple activities provided for the specified age group.

The system involves a java application program. The program can be compiled using javac cls/ChildrenLearningSystem.java from the src folder and then run with java cls.ChildrenLearningSystem command at the command prompt.

It would be better if there were a jar executable file but here the application only can be run from the command prompt.

Since it is an application, it will not run from a web browser unless there is the JNLP file that can launch the application through the java web start. Thanks to the recent java SE update 10, however, that would require server to hold the file. That Java application mentioned runs as standalone, outside the browser offering a secure environment.

On the other hand, applets, according to Sun Java Tutorial Websites, is a special kind of Java program that a browser enabled with Java technology can download from the internet and run within it. An applet is typically embedded inside a web-page and runs in the context of the browser. An applet must be a subclass of the java.applet.Applet class, which provides the standard interface between the applet and the browser environment.

The Children Learning System can be transform into an applet by simply removing the packaging. Although the program runs in the html file within that directory, but that would causes exception in the web browser as that supplies application kind of coding.

4

Page 5: Children Learning System Report

TCP 1311

(III) UML Diagrams

Use Case Diagram

5

Page 6: Children Learning System Report

TCP 1311

Class Diagram

6

Child User Matching-selectsObjectFrom

1 1

Number SetNumberQuestion

-selectsObjectFrom SetMatchingQuestion

Page 7: Children Learning System Report

TCP 1311

Sequence Diagram

7

The Child User

Menu: Object

selectsFromMenu()

View:Object Examine:Object

typeOfObject ()

chooses()

Input()

inputanswer()

validateAnswer()numberOfCorrect()

Page 8: Children Learning System Report

TCP 1311

Collaboration Diagram

State Diagram

8

Child User

selectsFromMenu()

2:chooses()

1:typeOfObject()

2.1: input()

Menu:Object View:Object

Examine:Object

object examine

input()

validate()

Page 9: Children Learning System Report

TCP 1311

(IV) Appendix

(A) Source code

// ChildrenLearningSystem.javapackage cls;

import cls.frames.WelcomeFrame;import java.awt.Dimension;import java.awt.Toolkit;import javax.swing.UIManager;

public class ChildrenLearningSystem { boolean packFrame = false;

//Construct the application public ChildrenLearningSystem() {

WelcomeFrame frame = new WelcomeFrame(); //Validate frames that have preset sizes //Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack(); } else { frame.validate(); } //Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) {

9

Page 10: Children Learning System Report

TCP 1311

frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); }

//Main method public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { e.printStackTrace(); } new ChildrenLearningSystem(); }}

//AboutBox.javapackage cls.about; import javax.swing.JDialog;import java.awt.event.ActionListener;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.ImageIcon;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.AWTEvent;import javax.swing.BorderFactory;import java.awt.event.WindowEvent;import java.awt.event.ActionEvent;

public class AboutBox extends JDialog implements ActionListener {

JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JPanel insetsPanel1 = new JPanel(); JPanel insetsPanel2 = new JPanel(); JPanel insetsPanel3 = new JPanel(); JButton button1 = new JButton();

10

Page 11: Children Learning System Report

TCP 1311

JLabel imageLabel = new JLabel(); JLabel label1 = new JLabel(); JLabel label2 = new JLabel(); JLabel label3 = new JLabel(); JLabel label4 = new JLabel(); ImageIcon image1 = new ImageIcon(); BorderLayout borderLayout1 = new BorderLayout(); BorderLayout borderLayout2 = new BorderLayout(); FlowLayout flowLayout1 = new FlowLayout(); GridLayout gridLayout1 = new GridLayout(); String product = "Children Learning System"; String version = "1.0"; String copyright = "Copyright (c) 2009"; String comments = "Simple learning system for children of ages between 4 to 10 years.";

public AboutBox() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } }

/* WelcomeFrame_AboutBox() { this(null); }*/

//Component initialization private void jbInit() throws Exception { image1 = new ImageIcon(cls.about.AboutBox.class.getResource("about.png")); imageLabel.setIcon(image1); this.setTitle("About"); panel1.setLayout(borderLayout1); panel2.setLayout(borderLayout2); insetsPanel1.setLayout(flowLayout1); insetsPanel2.setLayout(flowLayout1); insetsPanel2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); gridLayout1.setRows(4); gridLayout1.setColumns(1); label1.setText(product); label2.setText(version); label3.setText(copyright); label4.setText(comments); insetsPanel3.setLayout(gridLayout1); insetsPanel3.setBorder(BorderFactory.createEmptyBorder(10, 60, 10, 10));

11

Page 12: Children Learning System Report

TCP 1311

button1.setText("Ok"); button1.addActionListener(this); insetsPanel2.add(imageLabel, null); panel2.add(insetsPanel2, BorderLayout.WEST); this.getContentPane().add(panel1, null); insetsPanel3.add(label1, null); insetsPanel3.add(label2, null); insetsPanel3.add(label3, null); insetsPanel3.add(label4, null); panel2.add(insetsPanel3, BorderLayout.CENTER); insetsPanel1.add(button1, null); panel1.add(insetsPanel1, BorderLayout.SOUTH); panel1.add(panel2, BorderLayout.NORTH); setResizable(false); }

//Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { cancel(); } super.processWindowEvent(e); }

//Close the dialog void cancel() { dispose(); }

//Close the dialog on a button event public void actionPerformed(ActionEvent e) { if (e.getSource() == button1) { cancel(); } }}

//Matching.javapackage cls.core;

public class Matching { public Matching() { }

private String question; private String correctAnswer;

12

Page 13: Children Learning System Report

TCP 1311

private String option1; private String option2; private String option3; private String option4; private String option5;

public void setQuestion(String question) { this.question = question; }

public String getQuestion() { return this.question; }

public void setCorrectAnswer(String correctAnswer) { this.correctAnswer = correctAnswer; }

public String getCorrectAnswer() { return this.correctAnswer; }

public void setOption1(String option1) { this.option1 = option1; }

public String getOption1() { return this.option1; }

public void setOption2(String option2) { this.option2 = option2; }

public String getOption2() { return this.option2; } public void setOption3(String option3) { this.option3 = option3; }

public String getOption3() { return this.option3; } public void setOption4(String option4) { this.option4 = option4;

13

Page 14: Children Learning System Report

TCP 1311

}

public String getOption4() { return this.option4; } public void setOption5(String option5) { this.option5 = option5; }

public String getOption5() { return this.option5; }

public boolean checkAnswer(String givenAnswer) {

if (correctAnswer.compareTo(givenAnswer)==0) return true; else return false;

}

}

//Numbers.javapackage cls.core;

public class Numbers {

public Numbers() { }

private String operand1; private String operand2; private String operator; private String correctAnswer;

public void setOperand1(String operand1){ this.operand1 = operand1; } public String getOperand1(){ return this.operand1; }

14

Page 15: Children Learning System Report

TCP 1311

public void setOperand2(String operand2) { this.operand2 = operand2; }

public String getOperand2() { return this.operand2; }

public void setOperator(String operator) { this.operator = operator; }

public String getOperator() { return this.operator; }

public void setCorrectAnswer(String correctAnswer) { this.correctAnswer = correctAnswer; }

public String getCorrectAnswer() { return this.correctAnswer; }

public boolean checkAnswer(String givenAnswer){

if (correctAnswer.compareTo(givenAnswer)==0) return true; else return false;

}

}

//SetMatchingQuestion.javapackage cls.core.matching;

import cls.core.Matching;

public class SetMatchingQuestion extends Matching{

public SetMatchingQuestion(String question, String correctAns, String opt1, String opt2, String opt3, String opt4, String opt5) {

15

Page 16: Children Learning System Report

TCP 1311

super.setQuestion(question); super.setCorrectAnswer(correctAns); super.setOption1(opt1); super.setOption2(opt2); super.setOption3(opt3); super.setOption4(opt4); super.setOption5(opt5);

}

}

//SetNumberQuestion.javapackage cls.core.numbers;

import cls.core.Numbers;

public class SetNumberQuestion extends Numbers{ public SetNumberQuestion(String operand1, String operand2, String operator, String correctAns) {

super.setOperand1(operand1); super.setOperand2(operand2); super.setOperator(operator); super.setCorrectAnswer(correctAns);

}}

//AdditionSubtractionQuestions.javapackage cls.core.questions;

import cls.core.numbers.SetNumberQuestion;import cls.core.Numbers;

public class AdditionSubtractionQuestions{

public int totalQInt = 3;

public Numbers[] setQuestions(){

/*To add more questions just assign the correct no of questions to totalQInt and

16

Page 17: Children Learning System Report

TCP 1311

add one more same patern object of SetNumberQuestion */

Numbers[] questions = new SetNumberQuestion[totalQInt]; //(operand1, operand2, operator, correctAns) questions[0] = new SetNumberQuestion("3","4","+","7"); questions[1] = new SetNumberQuestion("8","6","+","14"); questions[2] = new SetNumberQuestion("5","2","-","3");

return questions;

}

}

//AnimalQuestions.javapackage cls.core.questions;

import cls.core.matching.SetMatchingQuestion;import cls.core.Matching;

public class AnimalQuestions{

public int totalQInt = 3;

public Matching[] setQuestions(){

/*To add more questions just assign the correct no of questions to totalQInt and add one more same patern object of SetMatchingQuestion */

Matching[] questions = new SetMatchingQuestion[totalQInt]; //(image path, correctAnswer, opt1, opt2, opt3, opt4, opt5) questions[0] = new SetMatchingQuestion("images/matching/animals/animal0.jpg","Buffalo","Lion","Elephant","Buffalo","Monkey","Camel"); questions[1] = new SetMatchingQuestion("images/matching/animals/animal1.jpg","Lion","Lion","Elephant","Buffalo","Monkey","Camel"); questions[2] = new SetMatchingQuestion("images/matching/animals/animal2.jpg","Elephant","Lion","Elephant","Buffalo","Monkey","Camel");

return questions;

17

Page 18: Children Learning System Report

TCP 1311

}

}

//ColorQuestions.javapackage cls.core.questions;

import cls.core.matching.SetMatchingQuestion;import cls.core.Matching;

public class ColorQuestions{

public int totalQInt = 3;

public Matching[] setQuestions(){

/*To add more questions just assign the correct no of questions to totalQInt and add one more same patern object of SetMatchingQuestion */

Matching[] questions = new SetMatchingQuestion[totalQInt]; //(image path, actualAnswer, opt1, opt2, opt3, opt4, opt5) questions[0] = new SetMatchingQuestion("images/matching/colors/color0.jpg","Green","Yellow","Green","Orange","Blue","Red"); questions[1] = new SetMatchingQuestion("images/matching/colors/color1.jpg","Blue","Yellow","Green","Orange","Blue","Red"); questions[2] = new SetMatchingQuestion("images/matching/colors/color2.jpg","Yellow","Yellow","Green","Orange","Blue","Red");

return questions;

}

}

//CountingQuestions.javapackage cls.core.questions;

18

Page 19: Children Learning System Report

TCP 1311

import cls.core.numbers.SetNumberQuestion;import cls.core.Numbers;

public class CountingQuestions{

public int totalQInt = 3;

public Numbers[] setQuestions(){

/*To add more questions just assign the correct no of questions to totalQInt and add one more same patern object of SetNumberQuestion */

Numbers[] questions = new SetNumberQuestion[totalQInt]; //(img path, "", "", correctAns) questions[0] = new SetNumberQuestion("images/numbers/counting/count0.JPG","","","3"); questions[1] = new SetNumberQuestion("images/numbers/counting/count1.JPG","","","5"); questions[2] = new SetNumberQuestion("images/numbers/counting/count2.JPG","","","6");

return questions;

}

}

//FruitQuestions.java package cls.core.questions;

import cls.core.matching.SetMatchingQuestion;import cls.core.Matching;

public class FruitQuestions{

public int totalQInt = 3;

public Matching[] setQuestions(){

/*To add more questions just assign the correct no of questions to totalQInt and add one more same patern object of SetMatchingQuestion */

Matching[] questions = new SetMatchingQuestion[totalQInt]; //(image path, correctAnswer, opt1, opt2, opt3, opt4, opt5)

19

Page 20: Children Learning System Report

TCP 1311

questions[0] = new SetMatchingQuestion("images/matching/fruits/fruit0.jpg","Orange","Mango","Orange","Banana","Grapes","Guava"); questions[1] = new SetMatchingQuestion("images/matching/fruits/fruit1.jpg","Mango","Mango","Orange","Banana","Grapes","Guava"); questions[2] = new SetMatchingQuestion("images/matching/fruits/fruit2.jpg","Grapes","Mango","Orange","Banana","Grapes","Guava");

return questions;

}

}

//MultiplicationDivisionQuestions.javapackage cls.core.questions;

import cls.core.numbers.SetNumberQuestion;import cls.core.Numbers;

public class MultiplicationDivisionQuestions{

public int totalQInt = 3;

public Numbers[] setQuestions(){

/*To add more questions just assign the correct no of questions to totalQInt and add one more same patern object of SetNumberQuestion */

Numbers[] questions = new SetNumberQuestion[totalQInt]; //(operand1, operand2, operator, correctAns) questions[0] = new SetNumberQuestion("2","2","*","4"); questions[1] = new SetNumberQuestion("6","2","*","12"); questions[2] = new SetNumberQuestion("9","3","/","3");

return questions;

}

}

20

Page 21: Children Learning System Report

TCP 1311

//MatchingFrame.javapackage cls.frames;

import java.awt.event.ActionListener;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.ImageIcon;import java.awt.AWTEvent;import java.awt.event.WindowEvent;import java.awt.event.ActionEvent;import javax.swing.JFrame;import java.awt.Toolkit;import java.awt.Dimension;import java.awt.Rectangle;import java.awt.Color;import cls.menubar.CLSMenuBar;import cls.core.questions.FruitQuestions;import cls.core.questions.AnimalQuestions;import cls.core.Matching;import cls.core.questions.ColorQuestions;

public class MatchingFrame extends JFrame {

Matching questions[]; private int qNo; private int totalQInt; private int totalRAnsInt; private String catStr; JPanel contentPane; JLabel imgLbl = new JLabel(); ImageIcon imgIcon; JButton optionBtn1 = new JButton(); JButton optionBtn2 = new JButton(); JButton optionBtn3 = new JButton(); JButton optionBtn4 = new JButton(); JButton optionBtn5 = new JButton(); JLabel ansLbl = new JLabel(); JButton nextBtn = new JButton(); JLabel totalRAnsLbl = new JLabel(); JLabel currQLbl = new JLabel(); JLabel totalQLbl = new JLabel();

//Construct the frame public MatchingFrame(String matchingCatStr) {

21

Page 22: Children Learning System Report

TCP 1311

enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { this.catStr = matchingCatStr; jbInit(); } catch(Exception e) { e.printStackTrace();

} }//End of constructor

private void setQuestions(){

if(catStr.compareTo("fruit")==0){ FruitQuestions questions = new FruitQuestions(); totalQInt = questions.totalQInt; //setQuestions also sets the questions and return those questions in array of Matching Class objects this.questions = questions.setQuestions();

} else if (catStr.compareTo("animal") == 0) { AnimalQuestions questions = new AnimalQuestions(); totalQInt = questions.totalQInt; this.questions = questions.setQuestions();

} else if (catStr.compareTo("color") == 0) { ColorQuestions questions = new ColorQuestions(); totalQInt = questions.totalQInt; this.questions = questions.setQuestions();

}

}

//Component initialization private void jbInit() throws Exception {

//Set questions setQuestions();

//Construct the MenuBar and set it for this frame CLSMenuBar clsMenuBar = new CLSMenuBar(this); this.setJMenuBar(clsMenuBar.getMenu());

contentPane = (JPanel) this.getContentPane();22

Page 23: Children Learning System Report

TCP 1311

contentPane.setLayout(null); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setSize(new Dimension(screenSize.width , screenSize.height-100));//Uncomment the above line after using design view and set the below line commented. //this.setSize(new Dimension(700, 650)); this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH); this.setTitle("Children Learning System");

//To display the imageicon in the label imgLbl.setBounds(new Rectangle(53, 80, 238, 234));

//Display 1st Question (starts from 0) displayQuestion(qNo);

//To display total question no. totalQLbl.setBounds(new Rectangle(30, 21, 163, 15)); totalQLbl.setFont(new java.awt.Font("Dialog", 1, 14)); totalQLbl.setText("Total Questions: " + totalQInt);

//To display current question no. currQLbl.setBounds(new Rectangle(55, 50, 110, 15)); currQLbl.setFont(new java.awt.Font("Dialog", 1, 12)); currQLbl.setText("Question No: " + (qNo+1));

//To display the label answer is wrong or right. ansLbl.setBounds(new Rectangle(84, 425, 243, 26)); ansLbl.setFont(new java.awt.Font("Dialog", 1, 14)); ansLbl.setVisible(false);

//To display Next Question Button nextBtn.setBounds(new Rectangle(440, 420, 137, 39)); nextBtn.setFont(new java.awt.Font("Dialog", 1, 14)); nextBtn.setText("Next Question"); nextBtn.setVisible(false);

//To display total right ans lable totalRAnsLbl.setBounds(new Rectangle(440, 415, 137, 39)); totalRAnsLbl.setForeground(Color.magenta); totalRAnsLbl.setFont(new java.awt.Font("Dialog", 1, 18)); totalRAnsLbl.setVisible(false);

//Add action listeners when answer is pressed. and next question button is pressed

optionBtn1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { whenAnswered(optionBtn1.getText()); }

23

Page 24: Children Learning System Report

TCP 1311

} );

optionBtn2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { whenAnswered(optionBtn2.getText()); } });

optionBtn3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { whenAnswered(optionBtn3.getText()); } } );

optionBtn4.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { whenAnswered(optionBtn4.getText()); } } );

optionBtn5.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { whenAnswered(optionBtn5.getText()); } } );

nextBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {

qNo = qNo + 1; currQLbl.setText("Question No: " + (qNo+1)); nextBtn.setVisible(false); ansLbl.setVisible(false); enableOptBtns(); displayQuestion(qNo);

} }

24

Page 25: Children Learning System Report

TCP 1311

);

//Add components to JPanel contentPane.add(optionBtn1, null); contentPane.add(optionBtn2, null); contentPane.add(optionBtn3, null); contentPane.add(optionBtn4, null); contentPane.add(optionBtn5, null); contentPane.add(imgLbl, null); contentPane.add(ansLbl, null); contentPane.add(nextBtn, null); contentPane.add(totalRAnsLbl, null); contentPane.add(totalQLbl, null); contentPane.add(currQLbl, null);

}//End of jbInit Method

private void displayQuestion(int qNo){

//Pass question's image path directly in the getResouce to edit it in design view imgIcon = new ImageIcon(cls.ChildrenLearningSystem.class.getResource(questions[qNo].getQuestion())); imgLbl.setIcon(imgIcon);

optionBtn1.setBounds(new Rectangle(440, 75, 137, 39)); optionBtn1.setFont(new java.awt.Font("Dialog", 1, 14)); optionBtn1.setText(questions[qNo].getOption1()); optionBtn2.setBounds(new Rectangle(440, 125, 137, 39)); optionBtn2.setFont(new java.awt.Font("Dialog", 1, 14)); optionBtn2.setText(questions[qNo].getOption2()); optionBtn3.setBounds(new Rectangle(440, 175, 137, 39)); optionBtn3.setFont(new java.awt.Font("Dialog", 1, 14)); optionBtn3.setText(questions[qNo].getOption3()); optionBtn4.setBounds(new Rectangle(440, 225, 137, 39)); optionBtn4.setFont(new java.awt.Font("Dialog", 1, 14)); optionBtn4.setText(questions[qNo].getOption4()); optionBtn5.setBounds(new Rectangle(440, 275, 137, 39)); optionBtn5.setFont(new java.awt.Font("Dialog", 1, 14)); optionBtn5.setText(questions[qNo].getOption5());}

private void whenAnswered(String givenAns){ //disable option buttons disableOptBtns();

//enable ansLbl ansLbl.setVisible(true);

25

Page 26: Children Learning System Report

TCP 1311

if (questions[qNo].checkAnswer(givenAns)) { totalRAnsInt = totalRAnsInt + 1; ansLbl.setForeground(Color.blue); ansLbl.setText("Good, Answer is Right!"); } else { ansLbl.setForeground(Color.red); ansLbl.setText("Sorry, Wrong Answer!"); }

//enable next question button till last question done if(qNo<totalQInt-1)//if not last question nextBtn.setVisible(true); else{// all question done whenAllQDone(); }

}

private void whenAllQDone(){ totalRAnsLbl.setText("Total Marks: "+ totalRAnsInt + "/" + totalQInt); totalRAnsLbl.setVisible(true); }

private void disableOptBtns(){ optionBtn1.setEnabled(false); optionBtn2.setEnabled(false); optionBtn3.setEnabled(false); optionBtn4.setEnabled(false); optionBtn5.setEnabled(false); }

private void enableOptBtns(){ optionBtn1.setEnabled(true); optionBtn2.setEnabled(true); optionBtn3.setEnabled(true); optionBtn4.setEnabled(true); optionBtn5.setEnabled(true); }

//Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } }

26

Page 27: Children Learning System Report

TCP 1311

}//End of class MatchingFrame

//NumberFrame.javapackage cls.frames;

import java.awt.event.ActionListener;import java.awt.AWTEvent;import java.awt.event.WindowEvent;import java.awt.event.ActionEvent;import java.awt.Toolkit;import java.awt.Dimension;import java.awt.Rectangle;import java.awt.Color;import cls.menubar.CLSMenuBar;import cls.core.questions.AdditionSubtractionQuestions;import cls.core.Numbers;import javax.swing.*;import cls.core.questions.MultiplicationDivisionQuestions;import cls.core.questions.CountingQuestions;

public class NumberFrame extends JFrame {

Numbers questions[]; private int qNo; private int totalQInt; private int totalRAnsInt; private String catStr; JPanel contentPane; JButton submitBtn = new JButton(); JLabel ansLbl = new JLabel(); JButton nextBtn = new JButton(); JLabel totalRAnsLbl = new JLabel(); JLabel currQLbl = new JLabel(); JLabel totalQLbl = new JLabel(); JLabel operandOneLbl = new JLabel(); JLabel operatorLbl = new JLabel(); JLabel operandTwoLbl = new JLabel(); JTextField ansTxtF = new JTextField(); JLabel equalLbl = new JLabel(); JLabel imgLbl = new JLabel(); ImageIcon imgIcon;

27

Page 28: Children Learning System Report

TCP 1311

//Construct the frame public NumberFrame(String numberCatStr) { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { this.catStr = numberCatStr; jbInit(); } catch(Exception e) { e.printStackTrace();

} }//End of constructor

private void setQuestions(){

if(catStr.compareTo("additionSubtraction")==0){ AdditionSubtractionQuestions questions = new AdditionSubtractionQuestions(); totalQInt = questions.totalQInt; this.questions = questions.setQuestions(); } if(catStr.compareTo("multiplyDivide")==0){ MultiplicationDivisionQuestions questions = new MultiplicationDivisionQuestions(); totalQInt = questions.totalQInt; this.questions = questions.setQuestions(); } if(catStr.compareTo("counting")==0){ CountingQuestions questions = new CountingQuestions(); totalQInt = questions.totalQInt; this.questions = questions.setQuestions(); }

}

//Component initialization private void jbInit() throws Exception {

//Set questions setQuestions();

//Construct the MenuBar and set it for this frame CLSMenuBar clsMenuBar = new CLSMenuBar(this); this.setJMenuBar(clsMenuBar.getMenu());

28

Page 29: Children Learning System Report

TCP 1311

contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(null); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setSize(new Dimension(screenSize.width , screenSize.height-100));//Uncomment the above line after using design view and set the below line commented. //this.setSize(new Dimension(700, 650)); this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH); this.setTitle("Children Learning System");

// Question area operandOneLbl.setFont(new java.awt.Font("Dialog", 1, 60)); operandOneLbl.setBounds(new Rectangle(75, 220, 115, 55)); operatorLbl.setFont(new java.awt.Font("Dialog", 1, 60)); operatorLbl.setBounds(new Rectangle(200, 220, 49, 55)); operandTwoLbl.setBounds(new Rectangle(332, 220, 115, 55)); operandTwoLbl.setFont(new java.awt.Font("Dialog", 1, 60)); equalLbl.setFont(new java.awt.Font("Dialog", 1, 60)); equalLbl.setText("="); equalLbl.setBounds(new Rectangle(472, 217, 41, 55)); ansTxtF.setFont(new java.awt.Font("Dialog", 1, 40)); ansTxtF.setBounds(new Rectangle(528, 220, 115, 55));//To display the imageicon in the label imgLbl.setBounds(new Rectangle(53, 85, 372, 319));

submitBtn.setBounds(new Rectangle(537, 310, 97, 39)); submitBtn.setFont(new java.awt.Font("Dialog", 1, 18)); submitBtn.setText("Submit");

//Display 1st Question (starts from 0) displayQuestion(qNo);

//To display total question no. totalQLbl.setBounds(new Rectangle(30, 21, 163, 15)); totalQLbl.setFont(new java.awt.Font("Dialog", 1, 14)); totalQLbl.setText("Total Questions: " + totalQInt);

//To display current question no. currQLbl.setBounds(new Rectangle(55, 50, 110, 15)); currQLbl.setFont(new java.awt.Font("Dialog", 1, 12)); currQLbl.setText("Question No: " + (qNo+1));

//To display the label answer is wrong or right. ansLbl.setBounds(new Rectangle(84, 425, 243, 26)); ansLbl.setFont(new java.awt.Font("Dialog", 1, 14)); ansLbl.setVisible(false);

//To display Next Question Button29

Page 30: Children Learning System Report

TCP 1311

nextBtn.setBounds(new Rectangle(440, 420, 137, 39)); nextBtn.setFont(new java.awt.Font("Dialog", 1, 14)); nextBtn.setText("Next Question"); nextBtn.setVisible(false);

//To display total right ans label totalRAnsLbl.setBounds(new Rectangle(440, 415, 137, 39)); totalRAnsLbl.setForeground(Color.magenta); totalRAnsLbl.setFont(new java.awt.Font("Dialog", 1, 18)); totalRAnsLbl.setVisible(false);

//Add action listeners when submit is pressed. and next question button is pressed

submitBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { whenAnswered(ansTxtF.getText().trim()); } } );

nextBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {

qNo = qNo + 1; currQLbl.setText("Question No: " + (qNo+1)); nextBtn.setVisible(false); ansLbl.setVisible(false); submitBtn.setVisible(true); ansTxtF.setEditable(true); ansTxtF.setText(""); displayQuestion(qNo);

} } );

//Add components to JPanel

contentPane.add(submitBtn, null); contentPane.add(ansLbl, null); contentPane.add(nextBtn, null);

30

Page 31: Children Learning System Report

TCP 1311

contentPane.add(totalRAnsLbl, null); contentPane.add(totalQLbl, null); contentPane.add(currQLbl, null); contentPane.add(operandOneLbl, null); contentPane.add(operandTwoLbl, null); contentPane.add(ansTxtF, null); contentPane.add(operatorLbl, null); contentPane.add(equalLbl, null); contentPane.add(imgLbl, null); contentPane.add(submitBtn, null);

}//End of jbInit Method

private void displayQuestion(int qNo){

if(catStr.compareTo("counting")==0){ imgIcon = new ImageIcon(cls.ChildrenLearningSystem.class.getResource(questions[qNo].getOperand1())); imgLbl.setIcon(imgIcon);

}else{

operandOneLbl.setText(questions[qNo].getOperand1()); operatorLbl.setText(questions[qNo].getOperator()); operandTwoLbl.setText(questions[qNo].getOperand2()); }}

private void whenAnswered(String givenAns){ //disable submit btn submitBtn.setVisible(false); ansTxtF.setEditable(false); //enable ansLbl ansLbl.setVisible(true);

if (questions[qNo].checkAnswer(givenAns)) { totalRAnsInt = totalRAnsInt + 1; ansLbl.setForeground(Color.blue); ansLbl.setText("Good, Answer is Right!"); } else { ansLbl.setForeground(Color.red); ansLbl.setText("Sorry, Wrong Answer!"); }

//enable next question button till last question done if(qNo<totalQInt-1)//if not last question nextBtn.setVisible(true);

31

Page 32: Children Learning System Report

TCP 1311

else{// all question done whenAllQDone(); }

}

private void whenAllQDone(){ totalRAnsLbl.setText("Total Marks: "+ totalRAnsInt + "/" + totalQInt); totalRAnsLbl.setVisible(true); }

//Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } }

}//End of class NumberFrame

//WelcomeFrame.javapackage cls.frames;

import javax.swing.JPanel;import javax.swing.JLabel;import java.awt.AWTEvent;import java.awt.event.WindowEvent;import javax.swing.JFrame;import java.awt.Toolkit;import java.awt.Dimension;import cls.menubar.CLSMenuBar;import java.awt.BorderLayout;

public class WelcomeFrame extends JFrame { JPanel contentPane; JLabel statusBar = new JLabel(); BorderLayout borderLayout1 = new BorderLayout();

//Construct the welcome frame public WelcomeFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); }

32

Page 33: Children Learning System Report

TCP 1311

catch(Exception e) { e.printStackTrace(); } }//End of constructor

//Component initialization private void jbInit() throws Exception {

//Construct the MenuBar and set it for this frame CLSMenuBar clsMenuBar = new CLSMenuBar(this); this.setJMenuBar(clsMenuBar.getMenu());

contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setSize(new Dimension(screenSize.width , screenSize.height-100)); this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH); this.setTitle("Children Learning System"); statusBar.setText("Children Learning System"); contentPane.add(statusBar, BorderLayout.SOUTH);

}//End of jbInit Method

//Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } }

}//End of class WelcomeFrame

//CLSMenuBar.javapackage cls.menubar;

import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import javax.swing.JFrame;import java.awt.Toolkit;import java.awt.Dimension;import java.awt.Dimension;

33

Page 34: Children Learning System Report

TCP 1311

import java.awt.Toolkit;import cls.about.AboutBox;import javax.swing.JMenuBar;import javax.swing.JMenu;import javax.swing.JMenuItem;import cls.frames.MatchingFrame;import cls.frames.NumberFrame;

public class CLSMenuBar{

JMenuBar jMenuBar = new JMenuBar(); JFrame jFrame;//The constructor. public CLSMenuBar(JFrame jframe) {

this.jFrame = jframe;

//Create each menu and item. JMenu jMenuFile = new JMenu(); JMenuItem jMenuFileExit = new JMenuItem();

JMenu jMenuHelp = new JMenu(); JMenuItem jMenuHelpAbout = new JMenuItem();

JMenu jMenuMatching = new JMenu(); JMenuItem jMenuMatchingFruits = new JMenuItem(); JMenuItem jMenuMatchingAnimals = new JMenuItem(); JMenuItem jMenuMatchingColors = new JMenuItem();

JMenu jMenuNumbers = new JMenu(); JMenuItem jMenuNumAddSub = new JMenuItem(); JMenuItem jMenuNumMultDiv = new JMenuItem(); JMenuItem jMenuNumCount = new JMenuItem();

//Setup the menu items jMenuFile.setText("File"); jMenuFileExit.setText("Exit"); jMenuHelp.setText("Help"); jMenuHelpAbout.setText("About"); jMenuMatching.setText("Matching"); jMenuMatchingFruits.setText("Fruits"); jMenuMatchingAnimals.setText("Animals"); jMenuMatchingColors.setText("Colors");

34

Page 35: Children Learning System Report

TCP 1311

jMenuNumbers.setText("Numbers"); jMenuNumAddSub.setText("Addition/Subtraction"); jMenuNumMultDiv.setText("Multiplication/Division"); jMenuNumCount.setText("Counting Objects");

//Add action listeners for the menu items.

//File | Exit action performed jMenuFileExit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { System.exit(0); } } );

//Matching | Fruits action performed jMenuMatchingFruits.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jFrame.dispose(); MatchingFrame matchingFruitsFrame = new MatchingFrame("fruit"); matchingFruitsFrame.setVisible(true); } } );

//Matching | Animals action performed jMenuMatchingAnimals.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jFrame.dispose(); MatchingFrame matchingAnimalsFrame = new MatchingFrame("animal"); matchingAnimalsFrame.setVisible(true);

} } );

//Matching | Colors action performed jMenuMatchingColors.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jFrame.dispose(); MatchingFrame matchingColorFrame = new MatchingFrame("color"); matchingColorFrame.setVisible(true);

} } );

35

Page 36: Children Learning System Report

TCP 1311

//Numbers | Addition/Subtraction action performed jMenuNumAddSub.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jFrame.dispose(); NumberFrame numberAdditionSubFrame = new NumberFrame("additionSubtraction"); numberAdditionSubFrame.setVisible(true); } } );

//Numbers | Multiplication/Subtraction action performed jMenuNumMultDiv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jFrame.dispose(); NumberFrame numberMultipDivFrame = new NumberFrame("multiplyDivide"); numberMultipDivFrame.setVisible(true); } } );

//Numbers | Counting Objects action performed jMenuNumCount.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jFrame.dispose(); NumberFrame numberCountingFrame = new NumberFrame("counting"); numberCountingFrame.setVisible(true); } } );

//Help | About action performed jMenuHelpAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {

AboutBox dlg = new AboutBox(); Dimension dlgSize = dlg.getPreferredSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); dlg.setLocation((screenSize.width - dlgSize.width) / 2, (screenSize.height - dlgSize.height) / 2); dlg.setModal(true); dlg.pack(); dlg.show(); }

36

Page 37: Children Learning System Report

TCP 1311

} );

//Organize all the items into a single menu. jMenuFile.add(jMenuFileExit); jMenuMatching.add(jMenuMatchingFruits); jMenuMatching.add(jMenuMatchingAnimals); jMenuMatching.add(jMenuMatchingColors); jMenuNumbers.add(jMenuNumAddSub); jMenuNumbers.add(jMenuNumMultDiv); jMenuNumbers.add(jMenuNumCount); jMenuHelp.add(jMenuHelpAbout);

jMenuBar.add(jMenuFile); jMenuBar.add(jMenuMatching); jMenuBar.add(jMenuNumbers); jMenuBar.add(jMenuHelp);

} //End of constructor.

//Method to get the menu bar from this menu. public JMenuBar getMenu() { return jMenuBar; }

}//End of class CLSMenuBar

(B) Sample interface screen

37

Page 38: Children Learning System Report

TCP 1311

(C) Sample input /output screens

A user can select from options in the menus.

Once User selects fruit from matching, this will appear and user has to choose the correct answer. Along each options the mouse rollover has effect.

38

Page 39: Children Learning System Report

TCP 1311

After selecting an option an output message will clarify the answer.

When user selects wrong a option the system will notify that the answer was wrong.

39

Page 40: Children Learning System Report

TCP 1311

There is some counting too.

40

Page 41: Children Learning System Report

TCP 1311

41

Page 42: Children Learning System Report

TCP 1311

A token of Appreciation

I, Mohgambihai A/P Moganalingam will like to thank my lecturer Mr. Md. Shohel Sayeed for helping me wonderfully in my entire understanding about Java and Object-Oriented

Programming.

Thank You Mr. Md. Shohel Sayeed

42