PDA

View Full Version : Java programming query


navjotjsingh
28-07-2007, 08:36 PM
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


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.

Charan
28-07-2007, 11:18 PM
What is the problem navjtoh? Though I dont know Java this looks very similar to C#. By looking at it , you may have some problem with event handler.

navjotjsingh
29-07-2007, 08:22 PM
Try running this code under JDK 1.6.0 and you will know what's the problem.

Hey no java programmer here? I want this answer fast.

navjotjsingh
04-08-2007, 04:10 PM
Hey, please somebody answer my query. I know there are many programmers here.

Posted screenshot of error:

http://img253.imageshack.us/img253/7226/javaerrorhj5.th.jpg (http://img253.imageshack.us/my.php?image=javaerrorhj5.jpg)

sachin_kothari
26-10-2007, 10:16 AM
^^ You are getting this error because you are using applets.
Untrusted Applets restricts access to files. You need to sign them to access files.
This (http://java.sun.com/sfaq/) should clarify your doubts.

navjotjsingh
27-10-2007, 12:38 AM
Thanks for such a speedy reply. I already fixed it. :D

Charan
27-10-2007, 01:09 AM
ROLF .. when I saw this thread bumped I thought navjoth still didnot fix the problem. :lol:

navjotjsingh
27-10-2007, 01:18 AM
^^ You are getting this error because you are using applets.
Untrusted Applets restricts access to files. You need to sign them to access files.
This (http://java.sun.com/sfaq/) should clarify your doubts.

second way is to use applet policy file which i did. :D