I'm trying to change the user inputted date into a date object so that i can format it into a date format then display it in the selected format in the textarea
import java.awt.*;
import java.awt.event.*;
import java.awt.CheckboxGroup;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class radiobutton extends Frame {
TextField textfield1;
TextField textfield2;
Button button;
TextArea textarea = new TextArea ("Enter a Date. \nThen Slect \nwhich Formant",15,15,15);
String temp;
public radiobutton() {
setSize(600, 400);
setTitle("Date Format Program");
setLayout(new FlowLayout());
textfield1 = new TextField("", 8);
final CheckboxGroup checkbox = new CheckboxGroup();
button = new Button("Click Me");
add(textfield1);
add(new Checkbox("MM/dd/yy", checkbox, false));
add(new Checkbox("dd-MMM-yy", checkbox, false));
add(new Checkbox("yy/MM/dd", checkbox, false));
add(button);
add(textarea);
addWindowListener( new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DateFormat df = new SimpleDateFormat();
checkbox.getSelectedCheckbox();
String choice = checkbox.toString(), date, datechanger;
date = textfield1.getText();
Date today = null;
try {
today = df.parse(date);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(choice.equals("java.awt.CheckboxGroup[selectedCheckbox=java.awt.Checkbox[checkbox0,177,146,40x23,label=one,state=true]]"))
{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yy");
datechanger = simpleDateFormat.format(today);
textarea.append("\n");
textarea.append(datechanger );
}
//System.out.println( checkbox );
else{
textarea.append("\n");
textarea.append( choice );
}
}
});
}
public static void main(String[] args)
{
radiobutton myGuiExampleObject = new radiobutton();
myGuiExampleObject.setVisible(true);
}
}