-
Noob requires much help
okay, im a 10th grader and in my intro to java class i have a 200 point project that needs to be done by tuesday, and i need some major 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
Similar Threads
-
Replies: 1
Last Post: 07-28-2005, 05:34 PM
-
By Goggy in forum VB Classic
Replies: 4
Last Post: 05-04-2005, 01:52 PM
-
By coleman01 in forum .NET
Replies: 0
Last Post: 04-08-2005, 01:45 PM
-
By Shravan in forum VB Classic
Replies: 0
Last Post: 04-29-2002, 03:33 AM
-
By Roman Fish in forum .NET
Replies: 0
Last Post: 03-31-2001, 11:51 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks