Re: subclass JPasswordField



markspace wrote:
Mike wrote:

Just pseudo code is enough, as long as I know the basic things to look
for (like how to add a document change listener to the PlainDocument
inside the JPasswordField & how to set the timer and all).


Well, my problem with your original code is it didn't do anything at
all. Some of this stuff is pretty basic. Typing "java <interface>
tutorial" into Google almost always brings up several code examples,
including the tutorials from Sun.

Let's see: Google "java document change listener". First link:

<http://java.sun.com/docs/books/tutorial/uiswing/events/documentlistener.html>


This example actually uses a JTextField, so bonus there because it shows
you how to set the change listener on a text field.

Google "java timer tutorial". First link:

<http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html>

I think you should at least be able to create those two classes and do a
little something with them, even if you're not sure how to finish the job.

Ok, so my main question now is: How to I get to the JPasswordField that
the DocumentListener is attached to? How do I reference it?

Here's the code so far:

class TimedPasswordListener implements DocumentListener, ActionListener {
Timer timer;
char echoChar;

public void insertUpdate(DocumentEvent e) {
showText(e, 3);
}

public void removeUpdate(DocumentEvent e) {
showText(e, 3);
}

public void changedUpdate(DocumentEvent e) {
// Plain text components do not fire these events
}

public void showText(DocumentEvent e, int timeOut) {
Document doc = (Document) e.getDocument();
// How do I set the echo char of the JPasswordField
// to '0' here, and how do I restore it again after
// timeOut seconds?
// echoChar = <JPasswordField>.getEchoChar();
// <JPasswordField>.setEchoChar(0);
timer = new Timer(timeOut * 1000, this);
timer.setRepeats(false);
timer.start();
}

@Override
public void actionPerformed(ActionEvent e) {
Document doc = (Document) e.getSource();
// How do I restore the echo char of the JPasswordField?
// <JPasswordField>.setEchoChar(echoChar);
}
}
.



Relevant Pages

  • Re: Pocket outlook - AppointmentsCollection class: ListChanged event
    ... void POOMHelper_OutlookItemChanged(PIMNotificationMessage notification, PIMItemType itemType, int itemOID, int databaseOID) ... static Timer timer= new Timer; ... Thread timerThread = timer.Start; ... public void SleepIntermittently ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Animating auto hide of JPanel inside a JFrame
    ... When the mouse is brought close to the top of the panel, a label 'slides' down ... public void actionPerformed ... private void positionLabel ... Timer class that is called back at intervals. ...
    (comp.lang.java.gui)
  • Re: subclass JPasswordField
    ... JPasswordField jpwd = new JPasswordField; ... class TimedPasswordListener implements DocumentListener, ActionListener { ... public void showText{ ... private char echoChar; ...
    (comp.lang.java.programmer)
  • Re: Change status bar text back to default 5 seconds after every change?
    ... private Timer timeReset = new Timer; ... public void OnTimerTick ... that I can't use the StatusBar's OnChange event (or ...
    (microsoft.public.dotnet.languages.csharp)
  • Panels on a BorderLayout
    ... I have just finished this application that draws a rectangle inside a panel & uses a thread or a timer to animate it. ... int size = 0; ... public void setSize{ ...
    (comp.lang.java.help)