السلام عليكم ورحمة الله وبركاته انا اخوكم مقيم فى ابريطانيه ولقد احببت الجافا ولا كن للأسف لا املك المعرفه التامه فيها وارجو مساعتدكم فى الموضوع اننى اتعامل بلغه الانخليزيه وارجو المعذره على ذلك لقد عملت جميع الخطوات ولا كن ينقصنى بعض الاشياء للأكتمال البرنامج رياضيات للأطفال ليساعدهم على معرفت مادة الرياضيات مع الشكر
1- PROVIDE A METHOD FOR PLAYERS TO TAKE TRUNS TO PLAY THE GAME
2-KEEP TRACK OF THE SCORE FOR EACH PLAYER
3-PROVIDE LEVELS OF DIFFICULTY
4- DISPLAY THE WINNER ( THE PLAYER WITH THE HIGHEST SCORE ) AT THE END OF THE GAME.
import java.awt
import java.awt.event
import javax.swing.*;
public class MathsGui
{
// instance variables - replace the example below with your own
private JPanel buttonPanel = new JPanel
private JPanel questionPanel = new JPanel
private JPanel playerPanel = new JPanel
private JFrame frame;
private JLabel label;
private JLabel p1;
private JLabel p2;
private JLabel p3;
private JLabel answer;
private JButton Q1;
private JButton Q2;
private JButton Q3;
private JButton Q4;
private JButton Q5;
private JButton Q6;
private JButton Q7;
private JButton Q8;
private JButton Q9;
private JButton Q10;
private JButton Ret;
private JButton submit;
private JTextField txtAnswer;
private int ans = 0;
private int p1score = 0;
private int p2score = 0;
private int p3score = 0;
private boolean swap;
private JTextArea jtxQuestion;
/**
* Constructor for objects of class MathsGui
*/
public MathsGui()
{
// initialise instance variables
MakeFrame();
}
private void MakeFrame()
{
swap = true;
frame = new JFrame();
Container contentPane = frame.getContentPane();
label = new JLabel("Mathematics Game Player 1 Turn: ");
p1 = new JLabel("Player 1 = " + p1score);
p2 = new JLabel("Player 2 = " + p2score);
p3 = new JLabel("Player 3 = " + p3score);
answer = new JLabel("Answer");
Q1 = new JButton("Q1");
Q2 = new JButton("Q2");
Q3 = new JButton("Q3");
Q4 = new JButton("Q4");
Q5 = new JButton("Q5");
Q6 = new JButton("Q6");
Q7 = new JButton("Q7");
Q8 = new JButton("Q8");
Q9 = new JButton("Q9");
Q10 = new JButton("Q10");
Ret = new JButton("Ret");
submit = new JButton("Submit Selection");
jtxQuestion = new JTextArea();
txtAnswer = new JTextField();
buttonPanel.setLayout(new GridLayout(6,2));
questionPanel.setLayout(new GridLayout(6,2));
playerPanel.setLayout(new FlowLayout());
playerPanel.add(label);
playerPanel.add(p1);
playerPanel.add(p2);
playerPanel.add(p3);
questionPanel.add(jtxQuestion);
questionPanel.add(txtAnswer);
questionPanel.add(submit);
buttonPanel.add(Q1);
buttonPanel.add(Q2);
buttonPanel.add(Q3);
buttonPanel.add(Q4);
buttonPanel.add(Q5);
buttonPanel.add(Q6);
buttonPanel.add(Q7);
buttonPanel.add(Q8);
buttonPanel.add(Q9);
buttonPanel.add(Q10);
buttonPanel.add(Ret);
contentPane.setLayout(new BorderLayout());
contentPane.add(playerPanel, BorderLayout.NORTH);
contentPane.add(buttonPanel, BorderLayout.WEST);
contentPane.add(questionPanel, BorderLayout.CENTER);
contentPane.add(answer, BorderLayout.SOUTH);
//contentPane.add(Q2, BorderLayout.WEST);
//contentPane.add(Q3, BorderLayout.WEST);
//contentPane.add(Q4, BorderLayout.WEST);
//contentPane.add(Q5, BorderLayout.WEST);
ButtonHandler handler = new ButtonHandler();
Q1.addActionListener(handler);
Q2.addActionListener(handler);
Q3.addActionListener(handler);
Q4.addActionListener(handler);
Q5.addActionListener(handler);
Q6.addActionListener(handler);
Q7.addActionListener(handler);
Q8.addActionListener(handler);
Q9.addActionListener(handler);
Q10.addActionListener(handler);
Ret.addActionListener(handler);
submit.addActionListener(handler);
frame.pack();
frame.setVisible(true);
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == Q1)
{
jtxQuestion.setText("What is 2x2");
ans = 4;
}
if(event.getSource() == Q2)
{
jtxQuestion.setText("What is 4x4");
ans = 16;
}
if(event.getSource() == Q3)
{
jtxQuestion.setText("What is 6x6");
ans = 36;
}
if(event.getSource() == Q4)
{
jtxQuestion.setText("What is 8-5");
ans = 3;
}
if(event.getSource() == Q5)
{
jtxQuestion.setText("What is 9-9");
ans = 0;
}
if(event.getSource() == Q6)
{
jtxQuestion.setText("Find the value of 5 + 22 - 8 + 3");
ans = 4;
}
if(event.getSource() == Q7)
{
jtxQuestion.setText("What is the value of 9 - [12 + (15 ÷ 3)]?");
ans = -8;
}
if(event.getSource() == Q8)
{
jtxQuestion.setText("Find the value of a - b2 if a = 4 and b = 3.");
ans = -5;
}
if(event.getSource() == Q9)
{
jtxQuestion.setText("What is the value of 9 - [14 + (15 ÷ 3)]?");
ans = -4;
}
if(event.getSource() == Q10)
{
jtxQuestion.setText("What is the value of 9 - [16 + (9 ÷ 3)]?");
ans = -3;
}
if(event.getSource() == Ret)
{
jtxQuestion.setText("new game");
ans = 0;
}
if(event.getSource() == submit)
{
int answers = Integer.parseInt(txtAnswer.getText());
if(answers == ans)
{
answer.setText("Answer is Correct");
if(swap)
{
p1score = p1score + 1;
p1.setText("Player 1 = " + p1score);
}
if(!swap)
{
p2score = p2score + 1;
p2.setText("Player 2 = " + p2score);
}
if(!swap)
{
p3score = p3score + 1;
p3.setText("Player 3 = " + p3score);
}
}
else
{
answer.setText("Answer is Incorrect");
}
swap = !swap;
if(swap)
{
label.setText("Mathematics Game Player 1 Turn: ");
}
if(!swap)
{
label.setText("Mathematics Game Player 2 Turn: ");
}
if(!swap)
{
label.setText("Mathematics Game Player 3 Turn: ");
}
}