We were asked to create an applet in which it will get the current date, then the user will input a number (n), when the user presses 'ok', the date+n after will display. Here is my code so far
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Calendar;
import java.util.Date.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class fcast extends Applet implements ActionListener
{
int num;
Date p;
Label ldate = new Label("Today is: ");
Label lfcast = new Label("No. of days before forecast: ");
Label lfcdate = new Label("Forecast Date: ");
TextField tdate = new TextField(" ",20);
TextField tfcast = new TextField(" ",20);
TextField tfcdate = new TextField(" ",20);
Button bk = new Button("OK");
Button bcr = new Button("CLEAR");
Calendar d=Calendar.getInstance();
SimpleDateFormat date = new SimpleDateFormat("MM dd yyyy");
Date d8 = new Date();
DateFormat df = DateFormat.getDateInstance();
public void init()
{
add(ldate); add(tdate);
add(lfcast); add(tfcast);
add(lfcdate); add(tfcdate);
add(bk); add(bcr);
bk.addActionListener(this);
bcr.addActionListener(this);
tdate.setText(date.format(d8));
}
public void actionPerformed(ActionEvent f)
{
if(f.getSource()==bk)
{
{
num=Integer.parseInt(tfcast.getText());
d.add(Calendar.DATE, num);
Date p=d.getTime();
tfcdate.setText(String.valueOf(p));
}
}
if(f.getSource()==bcr)
{
tdate.setEnabled(false);
tfcdate.setText(" ");
tfcast.setText(" ");
tfcast.requestFocus();
}
}
}
It doesn't output, what's wrong with my code? Thanks.