473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to addActionListener to the code below?

1
Good day,

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


Expand|Select|Wrap|Line Numbers
  1. import java.applet.Applet;
  2. import java.awt.TextField;
  3. import java.awt.Button;
  4. import java.awt.Label;
  5. import java.awt.Graphics;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.ActionEvent;
  8.  
  9.  
  10. public class Vivz extends Applet implements ActionListener{
  11.  
  12. Label lblProduct;
  13. Label lblPrice;
  14. Label lblQuantity;
  15. TextField txtProduct;
  16. TextField txtPrice;
  17. TextField txtQuantity;
  18. Button btnCalculate;
  19.  
  20. String total = "";
  21.  
  22. public void init()
  23. {
  24.     lblProduct = new Label("Enter the product ");
  25.     txtProduct = new TextField(20);
  26.     lblPrice = new Label("Enter the price ");
  27.     txtPrice = new TextField(20);
  28.     lblQuantity = new Label("Enter the quantity ");
  29.     txtQuantity = new TextField(20);
  30.     btnCalculate = new Button("Calculate Invoice");
  31.     btnCalculate.addActionListener(this);
  32.  
  33.  
  34.     add(lblProduct);
  35.     add(txtProduct);
  36.     add(lblPrice);
  37.     add(txtPrice);
  38.     add(lblQuantity);
  39.     add(txtQuantity);
  40.     add(btnCalculate);
  41.     add(lblResult);
  42.     }
  43.     public void actionPerformed(ActionEvent e)
  44.     { 
  45.  
  46.  }
  47.     }
Apr 17 '14 #1
1 1456
rajujrk
107 100+
Hi

Expand|Select|Wrap|Line Numbers
  1.         btnCalculate.addActionListener(new ActionListener() {
  2.             public void actionPerformed(ActionEvent e) {
  3.  
  4.                 // Do your Action Here
  5.  
  6.             }
  7.         });
  8.  
Thanks
Raju
Jul 4 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: samlicon | last post by:
i have a java project to do , but what problem i encounter is how to fill / put an image of jpeg into a Reatangle in the code below please type the code in detail since i am an entry level...
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
2
by: alexandre martins | last post by:
Every time i try to make Deserialize the computer gives me the folowing error: "End of Stream encountered before parsing was complete" the code that i'm running is simple and is based on an...
6
by: vbdog | last post by:
Hi I am trying to convert the vb6 code below into vb.net code can anyboddy help The vb6 code is from a chip8 Emulator that somboddy wrote. vb6 code this function keeps getting called until the...
8
by: jd2007 | last post by:
Why the Ajax code below in ajax.js is causing my form not to work ? ajax.js: var a=0; var b=0; var c=0; var d=0; var e=0; var f=0;
3
by: yxq | last post by:
How to convert the C# code below to VB.NET? thank you. AddLogicalDrive(((char)('A' + i)).ToString() + ":");
0
by: yxq | last post by:
Hello, The code below can popup the property dialog of a file, it works well on XP, Vista 32bit, but it will not work on Vista 64bit, how to correct it? i have tried to change integer to intptr,...
3
by: uma9 | last post by:
hi, the code below is used to insert a single record....i want to know how to insert multiple records using a "for" loop...please help Set connect = CreateObject ("ADODB.Connection")...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.