setEchoCharacter and some more

Eric Smalley (ericsmal@xs4all.nl)
Sun, 26 Oct 1997 21:29:26 -0700

Message-Id: <1.5.4.32.19971027042926.006760d8@xs4all.nl>
Date: Sun, 26 Oct 1997 21:29:26 -0700
To: java-security@web2.javasoft.com
From: Eric Smalley <ericsmal@xs4all.nl>
Subject: setEchoCharacter and some more

Hi there,

My name is Eric Smalley, currently learning java 1.1.

Forgive me if I have not mailed the proper address concerning the second
question I have, but at one glance at your tremendous amount of
emailaddresses I couldn't find the proper one. Maybe you would be so kind to
forward the question, or maybe you are so kind to resolve it for me.

In any case, thanks in advance.

Question 1:
I have been trying to create a password based program and have managed to
"Equal" a String (containing the password) to the outcome of a button, that
processes the password that was typed into a textfield...and then if the
String matches the password that was typed in the textfield..it opens a
frame for instance.

I used the following code to equal the string to the typed password:

"
if(e.getSource() == button1) {
if(text1.getText().equals(string1)) {
"

string1 was defined as String string1;
and then in the init() function: string1 = new String("abcde");

My problem however is to convert the typed characters in the TextField to a
"*" character. This to ensure that not even people that are watching the
screen when the password is typed, know what the password is.

I know you should be able to use the setEchoChar(char) function, and I tried
it as followed (I showed the complete applet, but I pointed out the specific
trouble section with an arrow( ==>) ):

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class password extends Applet implements ActionListener {

Button button1;
TextField text1;
passFrame frame1;
String string1;

public void init() {

text1 = new TextField(5);
add(text1);
text1.addActionListener(this);

button1 = new Button("Access information");
add(button1);
button1.addActionListener(this);

string1 = new String("abcde");

frame1 = new passFrame("Password Frame");
frame1.resize(150, 100);
}

public void actionPerformed(ActionEvent e) {

if(e.getSource() == button1) {
==> text1.setEchoChar("*");
if(text1.getText().equals(string1)) {
frame1.show();
text1.setText("");
}
}
}
}

class passFrame extends Frame implements ActionListener {

Label label1;
Button button2;

passFrame(String title) {
super(title);

label1 = new Label("Password accepted!", Label.CENTER);
add(label1);

button2 = new Button("Exit");
add(button2);
button2.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {
if(e.getSource() == button2) {
hide();
}
}
}

___________

My second problem, or better said, lacking knowledge, concerns the writing
away of strings (that are for instance typed into a textfield) into a file,
and then retrieving it again.

I was wondering if you could give me an example of how to write such a code.

For instance, I would like to be able to write away in, and retrieve from a
.txt file from a TextArea/TextField.

Some extra codes, like how to let the text appear at the line below the one
that was previously typed from, when that text exceeds the border of the
textarea, would be much appreciated.

___________

Please excuse me for the long letter. Just sending you enough information
that might be of use to you when possibly helping me out.

Thanks a lot,
Eric Smalley
Director - Owner of PC Net Solutions