navjotjsingh
Wise Old Owl
I have a problem with the following java program. I am using JDK 1.6.0
Can somebody suggest solution to the problem?
Here is the code
Please help.
Can somebody suggest solution to the problem?
Here is the code
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
//<applet code=Login height=300 width=400></applet>
public class Login extends JApplet implements ActionListener
{
JTextField textCustName;
JPasswordField textPassword;
JLabel labelCustName, labelPassword;
JButton loginButton;
public void init()
{
createApplet();
}
public void createApplet()
{
JPanel panel;
panel = new JPanel();
getContentPane().add(panel);
panel.setLayout(new FlowLayout());
labelCustName = new JLabel("Customer login Name:");
textCustName = new JTextField(10);
labelPassword = new JLabel("Password:");
textPassword = new JPasswordField(10);
loginButton = new JButton("Login");
panel.add(labelCustName);
panel.add(textCustName);
panel.add(labelPassword);
panel.add(textPassword);
panel.add(loginButton);
loginButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
Object obj = evt.getSource();
if (obj == loginButton)
{
String entry = textCustName.getText() + ":" + new String(textPassword.getPassword());
try
{
RandomAccessFile logfile = new RandomAccessFile("Customer.txt","rw");
logfile.seek(logfile.length());
logfile.writeBytes(entry);
}
catch(IOException e)
{
showStatus("Cannot write on to the logfile"+e);
}
}
}
}
Please help.