hi every one
i am new to java and object oriented programming.my problem is that i wanna acces a text field...in a frame i created a text area and a button.i want to populate textarea when the button is clicked..i know it is very simple to you but i have been struggling with this for hours.....below is the source code...
thanx in advance
----------------------
/*
* i am trying to populate a textfield or textarea when a button is clicked...
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.Button;
public class ForTestPurposesOnly extends GUIFrame
implements TextListener,ActionListener{
String msg=new String(" ");
int flag =0;
public ForTestPurposesOnly(){
super("Buttons And Text components together");
Button button=new Button("Click me!!!!");
button.addActionListener(this);
add(button,BorderLayout.SOUTH);
setSize(100,100);
setVisible(true);
TextField tf=new TextField();
tf.addTextListener(this);
add(tf,BorderLayout.NORTH);
pack();
}
public void actionPerformed(ActionEvent event){
if (event.getSource() instanceof Button){
System.out.println();
if (flag==0){
flag=1;
}
else{
flag=0;
}
}
}
public void textValueChanged(TextEvent event){
TextComponent src=(TextComponent)event.getSource();
if(flag==1){
src.setText("murtaza");
}
else{
src.setText("");
}
}
public static void main(String args[]){
new ForTestPurposesOnly();
}
}