Hi,
I am developing a swing application and I need to be able to clear or reset all textfields radiobuttons ect.. to empty strings or their default value.
So I am writting a method that will use getComponentCount to find out how many components are on the form and then loop through them and reset them.
like this
import java.awt.event.*;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.Component;
public class ClearActionListener implements ActionListener {
private JPanel p;
private Component comp;
private JPanel panel = new customerInfo_panel();
private JTextField text;
private JTextArea area;
private JCheckBox chkbox;
/** Creates new ClearActionListener */
public ClearActionListener(JPanel p) {
}
public void actionPerformed(ActionEvent evt){
String command = evt.getActionCommand();
int iCount;
iCount = 0;
if (command == "clear")
iCount = panel.countComponents();
/* while( iCount <= panel.countComponents())
{
if(comp.equals(text))
text.setText(" ");
else if(comp.equals(area))
area.setText(" ");
else if(comp.equals(chkbox))
chkbox.setSelected(false);
}*/
System.out.println("the name of the JPanel is " + panel);
System.out.println("the count of the components on the panel is "+ iCount);
System.out.println("In the actionPerformed method in the ClearActionListener class");
}
}
the problem being that iCount always returns 0.
therefore my question is how does one get this method to work.
sorry this is such a long post