Noob requires much help
my assignment is to create an applet that accepts dates in the format ##/##/## and out puts them in a "month" "day", year format. we are to assume that the user will input the date as ##/##/## including the slashes.
years 11-999 are to be outputted as years 1911-1999 and years 0-10 are to be outputted as 2000-2010
also no false days are to be outputted such as april 31, year because there is no 31st in april and leap years are also to be outputted when a true leap year is entered.
ex. user inputs 7/11/90, the program should output July 11, 1990
ex. user inputs 07/11/01, the program should output July 11, 2001
ex. user inputs 6/31/95, the program should output an error message because there is no 31st in June
here is what i have so far
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
import java.applet.*;
//Ivan Jones
//an applet to accept dates in one format and ourput them in another
//10/21/05
public class DateConverter extends Applet implements ActionListener
{
TextField tf1 = new TextField();
Button button = new Button("change date");
Color purple = new Color(150,20,150);
String date;
//variable isvalid is used to determine wether or not
//the string date is in the right syntax to be outputted
boolean isvalid;
String month;
String day;
String year;
int firstspace,lastspace;
public void init ()
{
this.setLayout(null);
tf1.setBounds(200,10,100,20);
this.add(tf1);
tf1.addActionListener(this);
tf1.setBackground(Color.white);
tf1.setForeground(purple);
button.setBounds(175,455,150,20);
this.add(button);
button.addActionListener(this);
button.setBackground(Color.white);
button.setForeground(purple);
}
public void paint (Graphics g)
{
g.setColor(purple);
g.fillOval(0,0,500,500);
g.setColor(purple);
g.drawString("Enter the Date here:",10,25);
g.setColor(Color.white);
//outputting the variables
g.drawString(date,225,100);
g.drawString(""+month,240,120);
g.drawString(""+day,240,140);
g.drawString(""+year,240,160);
}
public void actionPerformed (ActionEvent e)
{
if(e.getSource()==button)
{
date=tf1.getText();
//replaces "/"'s to spaces to work with indexOf method
date=date.replaceAll("/"," ");
//finds the first instance of a space in the variable "date"
firstspace=date.indexOf(" ");
//finds the last instance of a space in the variable date
lastspace=date.lastIndexOf(" ");
//assigns variables month, day, and year to substrings
//of variable date using the place where the first and last
//spaces are in the string
month=date.substring(0,firstspace);
day=date.substring(firstspace+1,lastspace);
year=date.substring(lastspace+1);
}
repaint();
}
}
any help or advice on what methods to use and how to use them would be greatly appreciated since i have only been programming for less than 1 month

