• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem about calling the component  RSS feed

Jess Ishasder
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created an applet with JTabbedPane on it. For each tab , I created a panel.
Suppose I have a JTextField object on a panel
1) How can I call that textfield?
2) How can I add actionListener to that textfield?
Part of my code is here:
ublic class Exercise3 extends JApplet{
JTabbedPane tabbedPane=null;
JPanel panel1=null;

public void init(){
//Create a tabbed pane
tabbedPane = new JTabbedPane();

//Add the panels to the tabbed pane
Container c = getContentPane();

}//End of init()
public void createPanel1(){

//Create panel1
panel1 = new JPanel();
JTextField txtEntry = new JTextField(20);
/*==============Add listener============*/
txtEntry.addActionListener(new TextFieldHandlerPanel1());<---"What should I put here to act as the argument of TextFieldHandlerPanel1?"
}//End of createPanel1()
class TextFieldHandlerPanel1 implements ActionListener{
public TextFieldHandlerPanel1(){
//Define method---actionPerformed()
public void actionPerformed(ActionEvent e){
String s = txtEntry.getText().trim();<--"How can I call txtEntry?"
}//End of TextFieldHandlerPanel1
Thank you for your help!!! :roll:
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ActionEvent gives you the component that the event was generated within:
You can perform the following:

NOTE: Your user name chosen here is invalid. If you wish to continue posting please read the naming policy and re-register with a valid name (i.e., first name + space + last name).
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!