import java.applet.*;
import java.awt.*;

public class JavaQuiz extends Applet {

    TextField answer1;
    Label question1;
    AudioClip beep;
    AudioClip ding;
    
    public void init() {
    
       beep = getAudioClip(getCodeBase(), "beep.au");
       ding = getAudioClip(getCodeBase(), "ding.au");
       setBackground(new Color(255,222,173));
       answer1 = new TextField (20);
       question1 = new Label("How much is 2 plus 2?");
       add(question1);
       add(answer1);
       validate();
    }

    public boolean action(Event evt, Object arg) {

       if (answer1.getText().indexOf("4") != -1) {
         answer1.selectAll();
         answer1.setText("Right!");
         ding.play();
       } 
       else {
         answer1.selectAll();
         answer1.setText("Sorry, try again.");
         answer1.selectAll();
         beep.play();
       }
       return true;
    }
}
