I provided this tip to VB programmers about a year ago. So here it is for our Java programmers.
This tip will clear all the text in a text box. This is a applet so the HTML file can be found at the end of the tip.
============================================
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ClearTextBoxes extends Applet implements
ActionListener {
TextField t1;
TextField t2;
TextField t3;
TextField t4onPanel;
Panel p1;
Button b;
public void init() {
add(t1= new TextField(20));
add(t2= new TextField(20));
add(t3= new TextField(20));
t4onPanel = new TextField(20);
p1 = new Panel();
p1.setBackground(new Color(0).yellow);
p1.add(t4onPanel);
add(p1);
add(b = new Button("reset TextFields"));
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == b)
resetTextFields(this);
}
public static void resetTextFields(Container c) {
Component [] components = c.getComponents();
for (int i = 0; i < components.length; i++ ) {
if (components[i] instanceof Container)
resetTextFields((Container) components[i]) ;
else if (components[i] instanceof TextField)
((TextField) components[i]).setText("") ;
}
}
}
============== HTML file ===================
<
HTML>
< TITLE>< /TITLE>
< BODY>
<
APPLET CODE="ClearTextBoxes.class">
<
/APPLET>
< /BODY>< /HTML>