SlideShare a Scribd company logo
The addButton_Click procedure should perform the following three tasks:
1.add the integer entered in the numTextBox to an accumulator
2. display the integer on a separate line in the ListTextBox
3. display the accumulator's value in the sumLabel.
How can I accomplish this using a TextBox instead of an InputBox(with prompts)?
Solution
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
*/
public class Cal extends Applet
implements ActionListener
{
String msg=" ";
int v1,v2,result;
TextField t1;
Button b[]=new Button[10];
Button add,sub,mul,div,clear,mod,EQ;
char OP;
public void init()
{
Color k=new Color(120,89,90);
setBackground(k);
t1=new TextField(10);
GridLayout gl=new GridLayout(4,5);
setLayout(gl);
for(int i=0;i<10;i++)
{
b[i]=new Button(""+i);
}
add=new Button("add");
sub=new Button("sub");
mul=new Button("mul");
div=new Button("div");
mod=new Button("mod");
clear=new Button("clear");
EQ=new Button("EQ");
t1.addActionListener(this);
add(t1);
for(int i=0;i<10;i++)
{
add(b[i]);
}
add(add);
add(sub);
add(mul);
add(div);
add(mod);
add(clear);
add(EQ);
for(int i=0;i<10;i++)
{
b[i].addActionListener(this);
}
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
mod.addActionListener(this);
clear.addActionListener(this);
EQ.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
char ch=str.charAt(0);
if ( Character.isDigit(ch))
t1.setText(t1.getText()+str);
else
if(str.equals("add"))
{
v1=Integer.parseInt(t1.getText());
OP='+';
t1.setText("");
}
else if(str.equals("sub"))
{
v1=Integer.parseInt(t1.getText());
OP='-';
t1.setText("");
}
else if(str.equals("mul"))
{
v1=Integer.parseInt(t1.getText());
OP='*';
t1.setText("");
}
else if(str.equals("div"))
{
v1=Integer.parseInt(t1.getText());
OP='/';
t1.setText("");
}
else if(str.equals("mod"))
{
v1=Integer.parseInt(t1.getText());
OP='%';
t1.setText("");
}
if(str.equals("EQ"))
{
v2=Integer.parseInt(t1.getText());
if(OP=='+')
result=v1+v2;
else if(OP=='-')
result=v1-v2;
else if(OP=='*')
result=v1*v2;
else if(OP=='/')
result=v1/v2;
else if(OP=='%')
result=v1%v2;
t1.setText(""+result);
}
if(str.equals("clear"))
{
t1.setText("");
}
}
}

More Related Content

PDF
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
PPTX
Awt components
PDF
Advanced Java - Practical File
PPTX
DOCX
OOP program questions with answers
DOCX
C# labprograms
PPTX
Loop structures chpt_6
PDF
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Awt components
Advanced Java - Practical File
OOP program questions with answers
C# labprograms
Loop structures chpt_6

Similar to The addButton_Click procedure should perform the following three tas.pdf (20)

PDF
Container adapters
PPTX
Java calculator
PDF
Java Week6(B) Notepad
PDF
I really need help with my C++ assignment. The following is the info.pdf
PPT
Chapter 5 GUI for introduction of java and gui .ppt
PDF
Hello, I need some assistance in writing a java program THAT MUST US.pdf
PDF
Introduction to python programming
DOCX
Bis 311 final examination answers
DOC
Design and analysis of algorithm MC9229-DAA-L-LM.doc
DOCX
New microsoft office word document
PDF
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
PDF
An object of class StatCalc can be used to compute several simp.pdf
PDF
The Ring programming language version 1.3 book - Part 13 of 88
PDF
C++ TUTORIAL 5
PPTX
Object Oriented Programming using C++: C++ Templates.pptx
DOCX
Use the following data set that compares age to average years lef.docx
DOCX
Basic calculator tutorial
PDF
Creating a Facebook Clone - Part XXIX - Transcript.pdf
PDF
Java File
PDF
C# Starter L04-Collections
Container adapters
Java calculator
Java Week6(B) Notepad
I really need help with my C++ assignment. The following is the info.pdf
Chapter 5 GUI for introduction of java and gui .ppt
Hello, I need some assistance in writing a java program THAT MUST US.pdf
Introduction to python programming
Bis 311 final examination answers
Design and analysis of algorithm MC9229-DAA-L-LM.doc
New microsoft office word document
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
An object of class StatCalc can be used to compute several simp.pdf
The Ring programming language version 1.3 book - Part 13 of 88
C++ TUTORIAL 5
Object Oriented Programming using C++: C++ Templates.pptx
Use the following data set that compares age to average years lef.docx
Basic calculator tutorial
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Java File
C# Starter L04-Collections

More from arbaazrabs (20)

PDF
Find the indicial roots then solve the following ODE using series. Yo.pdf
PDF
Design verilog code [in ISE Project Navigator Verilog Module, Veril.pdf
PDF
DNA and RNA are both stands of nucleotides but RNA can carry out for .pdf
PDF
Distinguish between the concepts of stereotyping, prejudice, and dis.pdf
PDF
38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf
PDF
An octapeptide was hydrolyzed and the amino acids separated. It was .pdf
PDF
c. hydrophillic heads; sticking out toward the interior and exterior.pdf
PDF
Biology Lab questions1. Units of amino acid are carried to the ri.pdf
PDF
Why is it important to use several sources of power and influence, r.pdf
PDF
What is special about the colugos teethLower incisors are comb-li.pdf
PDF
write simple program in c++ in which source reads a file of integers.pdf
PDF
Write an example of a unit test for a Class methods using JUnitfr.pdf
PDF
whats in plasmaSolutionAnswerBlood is the fluid connecti.pdf
PDF
What is a reason we want to write in a concise manner 1. To elimina.pdf
PDF
What are the advantages of Credit Suisse’s new supplier managemente.pdf
PDF
The PRIMARY structure of a protein isformed by alpha helices and .pdf
PDF
The figure below shows the chromosomes in a cell for some species (.pdf
PDF
A mistake occurs during lambda phage excision from the E. coli genom.pdf
PDF
Assume a System Engineering class has 27 students, of which one thir.pdf
PDF
1.) Explain what type of mechanism and application use a  marine ste.pdf
Find the indicial roots then solve the following ODE using series. Yo.pdf
Design verilog code [in ISE Project Navigator Verilog Module, Veril.pdf
DNA and RNA are both stands of nucleotides but RNA can carry out for .pdf
Distinguish between the concepts of stereotyping, prejudice, and dis.pdf
38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf
An octapeptide was hydrolyzed and the amino acids separated. It was .pdf
c. hydrophillic heads; sticking out toward the interior and exterior.pdf
Biology Lab questions1. Units of amino acid are carried to the ri.pdf
Why is it important to use several sources of power and influence, r.pdf
What is special about the colugos teethLower incisors are comb-li.pdf
write simple program in c++ in which source reads a file of integers.pdf
Write an example of a unit test for a Class methods using JUnitfr.pdf
whats in plasmaSolutionAnswerBlood is the fluid connecti.pdf
What is a reason we want to write in a concise manner 1. To elimina.pdf
What are the advantages of Credit Suisse’s new supplier managemente.pdf
The PRIMARY structure of a protein isformed by alpha helices and .pdf
The figure below shows the chromosomes in a cell for some species (.pdf
A mistake occurs during lambda phage excision from the E. coli genom.pdf
Assume a System Engineering class has 27 students, of which one thir.pdf
1.) Explain what type of mechanism and application use a  marine ste.pdf

Recently uploaded (20)

PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
IGGE1 Understanding the Self1234567891011
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Trump Administration's workforce development strategy
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
Complications of Minimal Access-Surgery.pdf
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
advance database management system book.pdf
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Uderstanding digital marketing and marketing stratergie for engaging the digi...
LDMMIA Reiki Yoga Finals Review Spring Summer
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Chinmaya Tiranga quiz Grand Finale.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
IGGE1 Understanding the Self1234567891011
Share_Module_2_Power_conflict_and_negotiation.pptx
My India Quiz Book_20210205121199924.pdf
Trump Administration's workforce development strategy
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Introduction to pro and eukaryotes and differences.pptx
Complications of Minimal Access-Surgery.pdf
B.Sc. DS Unit 2 Software Engineering.pptx
advance database management system book.pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf

The addButton_Click procedure should perform the following three tas.pdf

  • 1. The addButton_Click procedure should perform the following three tasks: 1.add the integer entered in the numTextBox to an accumulator 2. display the integer on a separate line in the ListTextBox 3. display the accumulator's value in the sumLabel. How can I accomplish this using a TextBox instead of an InputBox(with prompts)? Solution import java.awt.*; import java.awt.event.*; import java.applet.*; /* */ public class Cal extends Applet implements ActionListener { String msg=" "; int v1,v2,result; TextField t1; Button b[]=new Button[10]; Button add,sub,mul,div,clear,mod,EQ; char OP; public void init() { Color k=new Color(120,89,90); setBackground(k); t1=new TextField(10); GridLayout gl=new GridLayout(4,5); setLayout(gl); for(int i=0;i<10;i++) { b[i]=new Button(""+i);
  • 2. } add=new Button("add"); sub=new Button("sub"); mul=new Button("mul"); div=new Button("div"); mod=new Button("mod"); clear=new Button("clear"); EQ=new Button("EQ"); t1.addActionListener(this); add(t1); for(int i=0;i<10;i++) { add(b[i]); } add(add); add(sub); add(mul); add(div); add(mod); add(clear); add(EQ); for(int i=0;i<10;i++) { b[i].addActionListener(this); } add.addActionListener(this); sub.addActionListener(this); mul.addActionListener(this); div.addActionListener(this); mod.addActionListener(this); clear.addActionListener(this); EQ.addActionListener(this); } public void actionPerformed(ActionEvent ae) {
  • 3. String str=ae.getActionCommand(); char ch=str.charAt(0); if ( Character.isDigit(ch)) t1.setText(t1.getText()+str); else if(str.equals("add")) { v1=Integer.parseInt(t1.getText()); OP='+'; t1.setText(""); } else if(str.equals("sub")) { v1=Integer.parseInt(t1.getText()); OP='-'; t1.setText(""); } else if(str.equals("mul")) { v1=Integer.parseInt(t1.getText()); OP='*'; t1.setText(""); } else if(str.equals("div")) { v1=Integer.parseInt(t1.getText()); OP='/'; t1.setText(""); } else if(str.equals("mod")) { v1=Integer.parseInt(t1.getText()); OP='%'; t1.setText(""); } if(str.equals("EQ"))
  • 4. { v2=Integer.parseInt(t1.getText()); if(OP=='+') result=v1+v2; else if(OP=='-') result=v1-v2; else if(OP=='*') result=v1*v2; else if(OP=='/') result=v1/v2; else if(OP=='%') result=v1%v2; t1.setText(""+result); } if(str.equals("clear")) { t1.setText(""); } } }