import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class LeapYearApplet extends Applet implements ActionListener
{
private TextField inField = new TextField(15); //GUI components
private TextField resultField = new TextField(15);
private Label promt1 = new Label("Input Year >>");
private Label promt2 = new Label(">> is a Leap Year = >>");
private Button FindYear = new Button ("Leap Year!");
private isLeapYear = new isLeapYear(); //The Leap Year object
}
public void init();
{ //Set up the user interface
add(promt1); //Input elements
add(inField);
add(FindYear); //Control Button
add(promt2); //Output elements
add(resultField);
//Register button with listeners
FindYear.addActionListener(this);
setSize(175,200);
}//int()
public void actionPerformed(ActionEvent e)
{
String inputStr = inField.getText(); //Get user's input
//Convert it to double
double userInput = Double.parseDouble(inputStr);
double result = 0;
if(e.getSource()FindYear) { //Process and report
result = year.isLeapYear(userInput);
resultField.setText("result="+ result);
}
2007-03-28
09:08:45
·
3 answers
·
asked by
tabbysp
2
in
Computers & Internet
➔ Programming & Design