import java.awt.*;
import java.sql.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
public class nava extends JFrame implements ActionListener
{
Button b1=new Button("clear");
TextField t1=new TextField();
public nava()
{
this.setLayout(new GridLayout(2,2));
b1.addActionListener(this);
this.setSize(200,200);
add(t1);
add(b1);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText(""); //without space
}
}
public static void main(String r[])
{
new nava().show();
}
}
On clicking the button b1 the TextField should get empty but it is not getting empty.The textfield just remain the same .But when I put space in the actionPerformed function it add a space in textfield. Please tell me what is the problem with the code.
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText(" "); //with space
}
}