/* * File: LeapYearApplet.java * Author: Java Java Java Staff * Description: This class provides a GUI to the Year class. The user inputs * an integer into a TextField, and this applet determines if the integer is * a leap year. The result is painted on the applet. */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class LeapYearApplet extends Applet implements ActionListener { private Label prompt; private TextField inputField; // User types input here. private boolean yearIsLeapYear; // Records result of leap year test. /** * init() sets up the applet's GUI. */ public void init() { //Insert your code here //set the initial value of yearIsLeapYear as "true" cause 2000 is our initial year //Create new label prompt //Create new TextField inputField //Make this applet listen to inputField //set inputField as Editable //Add prompt and inputField to Applet //Set size of the applet } // init() /** * paint() displays the result of the leap year test, which is * recorded in the yearIsLeapYear instance variable. */ public void paint (Graphics g) { if (yearIsLeapYear) g.drawString(inputField.getText() + " is a leap year.", 10, 50); else g.drawString(inputField.getText() + " is NOT a leap year.", 10, 50); inputField.setText(""); // Reset the input field } // paint() /** * actionPerformed() whenever the user types Enter in the inputField. * It reads the user's input and tests it for leap year, storing the * result in the yearIsLeapYear variable. It then repaints the applet. */ public void actionPerformed(ActionEvent e) { //Insert your code here // get the input from inputField and parse it to an "int" number, using Integer.parseInt() // set the value of yearIsLeapYear according to the input number repaint(); } // actionPerformed() } // LeapYearApplet