DIGIT-ARC read-only archive · snapshot: July 23, 2026

Java programming query

8 posts · originally from https://geek.digit.in/community/threads/java-programming-query.64100/

N
navjotjsingh Original post #1
Jul 28, 2007 at 8: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

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
RCuber #2
Jul 28, 2007 at 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.
N
Jul 29, 2007 at 8: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.
N
Aug 4, 2007 at 4:10 PM
Hey, please somebody answer my query. I know there are many programmers here.

Posted screenshot of error:

*img253.imageshack.us/img253/7226/javaerrorhj5.th.jpg
sachin_kothari
Oct 26, 2007 at 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 should clarify your doubts.
N
Oct 27, 2007 at 12:38 AM
Thanks for such a speedy reply. I already fixed it. :D
RCuber
RCuber #7
Oct 27, 2007 at 1:09 AM
ROLF .. when I saw this thread bumped I thought navjoth still didnot fix the problem. :lol:
N
Oct 27, 2007 at 1:18 AM
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