using buttons and checkboxes - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

using buttons and checkboxes

ricka138ricka138 Posts: 5Member
I need to use a single button and some checkboxes in my program. I have implements ItemListener in the header to use the checkboxes but how do I get the button to work. It needs to clear the text field. Do I need to implement the ActionListener some how?

Thanks!

Comments

  • zibadianzibadian Posts: 6,349Member
    : I need to use a single button and some checkboxes in my program. I have implements ItemListener in the header to use the checkboxes but how do I get the button to work. It needs to clear the text field. Do I need to implement the ActionListener some how?
    :
    : Thanks!
    :
    :
    Yes, you need to implement the ActionListener. This requires the actionPerformed(ActionEvent e) method, in which you can clear the text field (= set the text of the text field to an empty string). The button has a method called addActionListener() to link the ActionListener to it.
  • ricka138ricka138 Posts: 5Member
    : Yes, you need to implement the ActionListener. This requires the actionPerformed(ActionEvent e) method, in which you can clear the text field (= set the text of the text field to an empty string). The button has a method called addActionListener() to link the ActionListener to it.
    :

    Ok, how do i do that when my header is as follows:

    public class PetAdviceApplet extends Applet implements ItemListener

    I used the ItemListener so I could use the checkboxes as well. How do I use both checkboxes and a button. When I try to put the addActionListener() in with my button in the init() method I get an error that it cannot be applied?

    Any ideas?

    Thanks again!!!!
  • zibadianzibadian Posts: 6,349Member
    : : Yes, you need to implement the ActionListener. This requires the actionPerformed(ActionEvent e) method, in which you can clear the text field (= set the text of the text field to an empty string). The button has a method called addActionListener() to link the ActionListener to it.
    : :
    :
    : Ok, how do i do that when my header is as follows:
    :
    : public class PetAdviceApplet extends Applet implements ItemListener
    :
    : I used the ItemListener so I could use the checkboxes as well. How do I use both checkboxes and a button. When I try to put the addActionListener() in with my button in the init() method I get an error that it cannot be applied?
    :
    : Any ideas?
    :
    : Thanks again!!!!
    :
    You can add more than 1 interface to a class:
    [code]
    public class PetAdviceApplet extends Applet implements ItemListener, ActionListener
    [/code]

  • ricka138ricka138 Posts: 5Member
    : : : Yes, you need to implement the ActionListener. This requires the actionPerformed(ActionEvent e) method, in which you can clear the text field (= set the text of the text field to an empty string). The button has a method called addActionListener() to link the ActionListener to it.
    : : :
    : :
    : : Ok, how do i do that when my header is as follows:
    : :
    : : public class PetAdviceApplet extends Applet implements ItemListener
    : :
    : : I used the ItemListener so I could use the checkboxes as well. How do I use both checkboxes and a button. When I try to put the addActionListener() in with my button in the init() method I get an error that it cannot be applied?
    : :
    : : Any ideas?
    : :
    : : Thanks again!!!!
    : :
    : You can add more than 1 interface to a class:
    : [code]
    : public class PetAdviceApplet extends Applet implements ItemListener, ActionListener
    : [/code]
    :
    :

    Thankyou so much! That's the only thing I've been struggling with. Thanks again! God Bless!!!

Sign In or Register to comment.