🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #3086

Re: TextField - How to?

#3086
From: Regis Eloi
Date: Tue, 28 Apr 1998 00:00
41 lines
1749 bytes
Art Smith wrote:

> Hi,
>
> I'm trying to develop a class which extends TextField and impliments a
> keyPressed method which only accepts "integer" characters (0-9).

I'm not sure you need to develop a class to do that.

> What I can't figure out is how to disable the TextFields default echo.
> i.e. If the character 'a' is typed I don't want echoed back to the
> display.

You have to consume the event.

> Is there a standard method for trapping events so it won't get passed
> along?
>
> Below is my code so far. It isn't fancy.

No it wasn't ;^)

Here is an example:
TextField t = new TextField();
t.addKeyListener(new KeyAdapter() {
  public void keyTyped(KeyEvent e) {
    char c = e.getKeyChar();
    if (!Character.isDigit(c)) {e.consume;}
  }
});

Hope that helps,
    Regis
--
________________________________________________________________________
 Regis Eloi       mailto:R.Eloi@dcs.hull.ac.uk
 The University of Hull (England) - Department of Computer Science
 Institut d'Informatique d'Entreprise (France)
 My CV is on the Web at http://www-eleves.iie.cnam.fr/eloi/cv_en.html
________________________________________________________________________
Technical Details
Message-ID: <35459CC8.865ED892@dcs.hull.ac.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3544F974.A46C8412@stat.ufl.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,9ebd2b4613535c20
X-Google-Attributes: gid1089d0,public
From: Regis Eloi <R.Eloi@dcs.hull.ac.uk>
Subject: Re: TextField - How to?
Date: 1998/04/28
Message-ID: <35459CC8.865ED892@dcs.hull.ac.uk>
X-Deja-AN: 348359387
Content-Transfer-Encoding: 7bit
References: <3544F974.A46C8412@stat.ufl.edu>
Content-Type: text/plain; charset=us-ascii
Organization: University of Hull
Mime-Version: 1.0
Reply-To: R.Eloi@dcs.hull.ac.uk
Newsgroups: borland.public.jbuilder.java.api