• CONTEST ALERT - Experience the power of DDR5 memory with Kingston Click for details

Java programming query

Status
Not open for further replies.

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

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.
 

RCuber

The Mighty Unkel!!!
Staff member
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.
 
OP
N

navjotjsingh

Wise Old Owl
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.
 
Last edited:
OP
N

navjotjsingh

Wise Old Owl
Hey, please somebody answer my query. I know there are many programmers here.

Posted screenshot of error:

 
Last edited:

sachin_kothari

Ambassador of Buzz
^^ 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 should clarify your doubts.
 

RCuber

The Mighty Unkel!!!
Staff member
ROLF .. when I saw this thread bumped I thought navjoth still didnot fix the problem. :lol:
 
OP
N

navjotjsingh

Wise Old Owl
sachin_kothari said:
^^ 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 should clarify your doubts.

second way is to use applet policy file which i did. :D
 
Status
Not open for further replies.
Top Bottom