import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ChildAddition extends Applet implements ActionListener
{
Label lblnum1=new Label(" NUMBER 1");
Label lblnum2=new Label("NUMBER 2");
Label lblsum=new Label(" SUM");
Label lbloutcome=new Label(" OUTCOME");
TextField txtNum1=new TextField(17);
TextField txtNum2=new TextField(17);
TextField txtSum=new TextField(17);
TextArea txtAreaOutcome=new TextArea(5,26);
Button add=new Button(" Generate Numbers to Add ");
Button check=new Button("CHECK");
Button close=new Button(" close ");
//-----------------------------------------------------------declare essential labels,textArea,buttons,textFields
public void init()
{
add(lblnum1);
add(txtNum1);
add(lblnum2);
add(txtNum2);
add(lblsum);
add(txtSum);
add(lbloutcome);
add(txtAreaOutcome);
add(add);
add(check);
add(close);
add.addActionListener(this);
check.addActionListener(this);
close.addActionListener(this);
txtNum1.setEditable(false);
txtNum2.setEditable(false);
check.setEnabled(false);
txtAreaOutcome.setEnabled(false);
setBackground(new Color(136,207,149));
add.setBackground(new Color(179,173,231));
check.setBackground(new Color(179,173,231));
close.setBackground(new Color(179,173,231));
lblnum1.setBackground(new Color(136,207,149));
lblnum2.setBackground(new Color(136,207,149));
lblsum.setBackground(new Color(136,207,149));
lbloutcome.setBackground(new Color(136,207,149));
/*exit.setBackground(new Color(179,173,231));
num1.setBackground(new Color(136,207,149));
num2.setBackground(new Color(136,207,149));
sum.setBackground(new Color(136,207,149));
result.setBackground(new Color(136,207,149));*/
Font f1 = new Font("Comic Sans MS",Font.BOLD, 15);
lblnum1.setFont(f1);
lblnum2.setFont(f1);
lblsum.setFont(f1);
lbloutcome.setFont(f1);
add.setFont(f1);
check.setFont(f1);
close.setFont(f1);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == add)
{
int ranNum1, ranNum2;
ranNum1 = (int)(Math.random()*100+1);
txtNum1.setText(ranNum1+"");
ranNum2 = (int)(Math.random()*100+1);
txtNum2.setText(ranNum1+"");
txtSum.requestFocus();
txtSum.setText("");
check.setEnabled(true);
txtAreaOutcome.setFont(new Font("Comic Sans MS",Font.BOLD, 14));
txtAreaOutcome.setText("Now Enter the sum");
}
else if(ae.getSource() == check)
{
try
{
txtAreaOutcome.setFont(new Font ("Comic Sans MS",Font.BOLD,14));
int num1=Integer.parseInt(txtNum1.getText());
int num2=Integer.parseInt(txtNum2.getText());
int sum = Integer.parseInt(txtSum.getText());
if((num1+num2)==sum)
txtAreaOutcome.setText("Excellent\n Your answer is correct");
else
txtAreaOutcome.setText("Wrong Answer!\n"+"Correct Answer is="+(num1+num2)+"\nTry Agaijn.");
}
catch(NumberFormatException nfe)
{
txtAreaOutcome.setText("Please Enter the sum");
txtSum.setText("");
txtSum.requestFocus();
}
}
}
}
_________________
Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.