login

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class login extends JApplet implements ActionListener
{
JTextField textName;
JTextArea ta;
JPasswordField textPassword;
JButton okButton;
Date date;
GregorianCalendar gCal;
int ctr=0;
public void init()
{
CreateApplet();
}
public void CreateApplet()
{
Container content;
content = getContentPane();
content.setLayout(new FlowLayout());
JLabel labeluserName;
JLabel labelPassword;
labeluserName = new JLabel("User Name:");
textName = new JTextField(10);
labelPassword = new JLabel("Password:");
textPassword = new JPasswordField(10);
ta=new JTextArea(10,10);
okButton = new JButton("OK");
content.add(labeluserName);
content.add(textName);
content.add(labelPassword);
content.add(textPassword);
content.add(ta);
content.add(okButton);
okButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
Object obj = evt.getSource();
if(obj == okButton)
{
date = new Date();
gCal = new GregorianCalendar();
gCal.setTime(date);
String pass=textPassword.getText();
String entry = "User :"+ textName.getText()+ " Logged in: "+gCal.get(Calendar.HOUR)+":"+gCal.get(Calendar.MINUTE)+"Date:"+(gCal.get(Calendar.MONTH)+1)+"/"+gCal.get(Calendar.DATE)+"/"+gCal.get(Calendar.YEAR)+" with Password :"+pass;
ta.setText(entry);

try
{
RandomAccessFile logFile = new RandomAccessFile("log.txt","rw");
logFile.seek(logFile.length());
logFile.writeBytes(ta.getText());


}
catch(IOException e)
{
showStatus("Cannot write on to the log file"+e);
}
}

}
}

/*


*/

Comments

Popular Posts