Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: AWT
Expertise: Beginner
Mar 20, 1997



Application Security Testing: An Integral Part of DevOps

Responding to Mousedown Event in TextField

How can I respond to a mousedown event in a TextField?

From the Java 1.0.2 API specs:

"In Java 1.0, the AWT does not send mouse or focus events to a text area. In Java 1.1, the AWT sends the text area all mouse, keyboard, and focus events that occur over it."
This means you would have to wait until Java 1.1 is released and implemented in browsers like Netscape, HotJava, and Internet Explorer, or implement a custom TextField widget that accomplished what you wanted.

I wrote the following little applet just to convince myself that TextFields don't get MOUSE_DOWN events; and sure enough, the showStatus() method is never called.

import java.applet.*;
import java.awt.*;
import java.util.*;

public class MouseText extends Applet {

       public void init() {
               Panel namePanel = new Panel();
               Label nameLabel = new Label("User name: ");
               TextField username = new TextField(20);

       public synchronized boolean handleEvent(Event e) {
               if (e.target instanceof TextField &&
                       e.id == Event.MOUSE_DOWN) {
                       showStatus("MouseDown at: " + new Date() );
               return false;
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date