import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

public class registration
{
Timer timer;


private Frame f;
private MenuBar mb;
private Menu m1, m2;
private MenuItem mi1, mi2, mi3, mi4, mi0, mj1, mj2;
private TextField lname, fname, minitial, sNum, address, city, contact, email;
private Label lbl1, lbl2, lbl3, lbl4, lbl5, lbl6;
private Button show, save, open, clear, exit;

public void launchFrame()
{

f = new Frame("Student Organization Registration");

mb = new MenuBar();
m1 = new Menu("File");
m2 = new Menu("Help");

mi0 = new MenuItem("Show");
mi1 = new MenuItem("Save");
mi2 = new MenuItem("Open");
mi3 = new MenuItem("Clear");
mi4 = new MenuItem("Exit");

mj1 = new MenuItem("About Author");
mj2 = new MenuItem("About System");

mb.add(m1);
mb.setHelpMenu(m2);

m1.add(mi0);
m1.add(mi1);
m1.add(mi2);
m1.add(mi3);
m1.add(mi4);
m2.add(mj1);
m2.add(mj2);

lbl1 = new Label("Name");
lbl2 = new Label("Student Number: ");
lbl3 = new Label("Address:");
lbl4 = new Label("City: " );
lbl5 = new Label("Contact Number: ");
lbl6 = new Label("Email");

fname = new TextField(15);
minitial = new TextField(2);
lname = new TextField(20);
sNum = new TextField(10);
address = new TextField(25);
city = new TextField(8);
contact = new TextField(9);
email = new TextField(12);


f.setLayout(new GridLayout(6,1));

Panel p1 = new Panel();
p1.add(lbl1);
p1.add(fname);
p1.add(minitial);
p1.add(lname);
f.add(p1);

Panel p2 = new Panel();
p2.add(lbl2);
p2.add(sNum);
CheckboxGroup gender = new CheckboxGroup();
p2.add(new Checkbox("Male",gender,false));
p2.add(new Checkbox("Female",gender,false));
f.add(p2);

Panel p3 = new Panel();
p3.add(lbl3);
p3.add(address);
p3.add(lbl4);
p3.add(city);
f.add(p3);

Panel p4 = new Panel();
p4.add(lbl5);
p4.add(contact);
p4.add(lbl6);
p4.add(email);
f.add(p4);

Panel p0 = new Panel();
save = new Button("Save");
p0.add(save);
clear = new Button("Clear");
p0.add(clear);
exit = new Button("Exit");
p0.add(exit);
f.add(p0);

fname.setText("<First Name Here>");
lname.setText("<Last Name Here>");

f.setBackground(Color.gray);
f.setResizable(false);
f.setMenuBar(mb);
f.setSize(500,300);
f.setVisible(true);

// Attatching listeners to menu items and buttons

exit.addActionListener(new exitSoftware());
mi4.addActionListener(new exitSoftware());
clear.addActionListener(new clearText());
mi3.addActionListener(new clearText());

save.addActionListener(new saveText());
mi1.addActionListener(new saveText());

open.addActionListener(new openText());
mi2.addActionListener(new openText());
}



private class exitSoftware implements ActionListener {
public void actionPerformed(ActionEvent e) {

//===============================================

public Reminder(int seconds) {
timer = new Timer();
timer.schedule(new RemindTask(), seconds * 1000);
}

class RemindTask extends TimerTask {
public void run()
{
timer.cancel(); //Terminate the timer thread
System.exit(0);
}
}
//===============================================

int ok = JOptionPane.showConfirmDialog(null,"are you sure","Confirmation",JOptionPane.YES_NO_OPTION);
new Reminder(5);
if (ok == JOptionPane.YES_OPTION)
{ System.exit(0); }
else
{ }
}
}


private class clearText implements ActionListener {
public void actionPerformed(ActionEvent e) {
cleartxt();
}
}

private class saveText implements ActionListener {
public void actionPerformed(ActionEvent e) {
saveFiles();
}
}
private class openText implements ActionListener {
public void actionPerformed(ActionEvent e) {
openFiles();
}
}

// clearing all textfields
public void cleartxt()
{
fname.setText("");
minitial.setText("");
lname.setText("");
sNum.setText("");
address.setText("");
contact.setText("");
}

public void openFiles()
{
fname.setText("");
minitial.setText("");
lname.setText("");
sNum.setText("");
address.setText("");
contact.setText("");
}

// saving files into texts

public void saveFiles()
{
try
{
File fileNf = new File("FirstName.txt");
File fileNl = new File("LastName.txt");
File fileNm = new File("Middle.txt");
File fileS = new File("Student_Number.txt");
File fileA = new File("Address.txt");
File fileC = new File("Contact.txt");
File fileCy = new File("City.txt");

String Sfname = fname.getText();
String Sminitial = minitial.getText();
String Slname = lname.getText();
String SsNum = sNum.getText();
String Saddress = address.getText();
String Scontact = contact.getText();
String SCity = city.getText();

PrintWriter Nf = new PrintWriter(new FileWriter(fileNf));
PrintWriter Nl = new PrintWriter(new FileWriter(fileNl));
PrintWriter Nm = new PrintWriter(new FileWriter(fileNm));
PrintWriter S = new PrintWriter(new FileWriter(fileS));
PrintWriter A = new PrintWriter(new FileWriter(fileA));
PrintWriter C = new PrintWriter(new FileWriter(fileC));
PrintWriter Cy = new PrintWriter(new FileWriter(fileCy));

Nf.print(Sfname);
Nl.print(Slname);
Nm.print(Sminitial);
A.print(Saddress);
C.print(Scontact);
S.print(SsNum);
Cy.print(SCity);

Nf.close();
Nl.close();
Nm.close();
A.close();
C.close();
S.close();
}

catch(IOException e)
{
e.printStackTrace();
}
}
//=======================================MAIN METHOD
public static void main(String args[])
{

registration reg = new registration();
reg.launchFrame();
}
}


am just creating this simple registeration program, though not complete yet, i am having trouble because i want to put a timer on the exit optionpane, after 5 seconds or so that the user does not press anythin, it will return to the main method that is to launch the frame again