How to addActionListener to the code below?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dragy
    New Member
    • Mar 2014
    • 1

    How to addActionListener to the code below?

    Good day,

    I have created the Applet but i don't know how to code the button to work or addActionListen er. See below


    Code:
    import java.applet.Applet;
    import java.awt.TextField;
    import java.awt.Button;
    import java.awt.Label;
    import java.awt.Graphics;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    
    
    public class Vivz extends Applet implements ActionListener{
      
    Label lblProduct;
    Label lblPrice;
    Label lblQuantity;
    TextField txtProduct;
    TextField txtPrice;
    TextField txtQuantity;
    Button btnCalculate;
    
    String total = "";
    
    public void init()
    {
        lblProduct = new Label("Enter the product ");
        txtProduct = new TextField(20);
        lblPrice = new Label("Enter the price ");
        txtPrice = new TextField(20);
        lblQuantity = new Label("Enter the quantity ");
        txtQuantity = new TextField(20);
        btnCalculate = new Button("Calculate Invoice");
        btnCalculate.addActionListener(this);
      
    
        add(lblProduct);
        add(txtProduct);
        add(lblPrice);
        add(txtPrice);
        add(lblQuantity);
        add(txtQuantity);
        add(btnCalculate);
        add(lblResult);
        }
        public void actionPerformed(ActionEvent e)
        { 
              
     }
        }
    Last edited by Rabbit; Apr 17 '14, 03:33 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • rajujrk
    New Member
    • Aug 2008
    • 107

    #2
    Hi

    Code:
            btnCalculate.addActionListener(new ActionListener() {
            	public void actionPerformed(ActionEvent e) {
            		
            		// Do your Action Here
            		
            	}
            });
    Thanks
    Raju

    Comment

    Working...