SlideShare a Scribd company logo
ANS:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Frame extends JFrame {
private double tn = 0;//here declare the variables
private double tn2 = 0;
private byte nom = -1;
private JTextField jtf;
public Frame() {
JButton[] bn = new JButton[10];
for ( int i = 9; i >= 0; i--) {
bn[i] = new JButton(Integer.toString(i));
}
//here declare the buttons
JButton eb= new JButton("e1");
JButton cb= new JButton("C");
JButton ab= new JButton("+");
JButton sb= new JButton("-");
JButton mb= new JButton("*");
JButton db= new JButton("/");
JButton ab= new JButton("+");
JButton sb= new JButton("-");
//here to set the size,bg,dimensionals
jtf = new JTextField();
jtf.setPreferredSize(new Dimension(180, 30));
jtf.setBackground(Color.BLUE);
jtf.setEnabled(false);
jtf.setHorizontalAlignment(4);
jtf.setDisabledTextColor(Color.GREEN);
//here set the layouts
JPanel PM = new JPanel();
PM.setLayout(new BoxLayout(PM, BoxLayout.Y_AXIS));
JPanel pt = new JPanel();
pt.setPreferredSize(new Dimension(160, 20));
pt.add(jtf);
JPanel pnb = new JPanel();
pnb.setPreferredSize(new Dimension(160, 100));
for(int i = 9; i>=0; i--) {
pnb.add(bn[i]);
}
//here buttons add to panels
JPanel pb_nom = new JPanel();
pb_nom.setPreferredSize(new Dimension(160, 35));
pb_nom.add(eb);
pb_nom.add(cb);
pb_nom.add(mb);
pb_nom.add(db);
pb_nom.add(ab);
pb_nom.add(sb);
umo_ji[] pb_action = new umo_ji[10];
for ( int i = 0; i < 10; i++ ) {
pb_action[i] = new umo_ji(bn[i]);
bn[i].addActionListener(pb_action[i]);
}
//here perform action buttons
eb e1 = new eb();
eb.addActionListener(e1);
cb c = new cb();
cb.addActionListener(c);
mb e2 = new mb();
mb.addActionListener(e2);
db e3 = new db();
db.addActionListener(e3);
ab add = new ab();
ab.addActionListener(add);
Sub_But subtract = new Sub_But();
sb.addActionListener(subtract);
PM.add(pt);
PM.add(pnb);
PM.add(pb_nom);
add(PM);
//To set the title and size
setTitle("Button_Test");
setSize(180, 290);
setLocationByPlatform(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
}
private class umo_ji implements ActionListener {
//here implements actionlistener
private String c;
public umo_ji(JButton a) {
this.c = a.text_get();
}
public void actionPerformed(ActionEvent e) {
if (!jtf.text_get().equals("0.0")) {
jtf.text_set(jtf.text_get() + c);
} else {
jtf.text_set("");
actionPerformed(e);
}
}
}
private class eb implements ActionListener {
@Override//overide buttons
public void actionPerformed(ActionEvent e) {
tn2 = Double.parseDouble(jtf.text_get());
if (nom == 0) {
jtf.text_set(Double.toString((Math.round((tn / tn2) * 100)) / 100));
} else if (nom == 1) {
jtf.text_set(Double.toString(tn * tn2));
} else if (nom == 2) {
jtf.text_set(Double.toString(tn2 + tn));
} else if (nom == 3) {
jtf.text_set(Double.toString(tn - tn2));
} else {
jtf.text_set(String.valueOf(tn));
}
tn = Double.parseDouble(jtf.text_get());
}
}
private class cb implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
jtf.text_set("");
tn = 0;
tn2 = 0;
nom = -1;
}
}
private class db implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (tn == 0) {
tn = Double.parseDouble(jtf.text_get());
jtf.text_set("");
} else {
tn2 = Double.parseDouble(jtf.text_get());
jtf.text_set("");
}
nom = 0;
}
}
private class mb implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (tn == 0) {
tn = Double.parseDouble(jtf.text_get());
jtf.text_set("");
} else {
tn2 = Double.parseDouble(jtf.text_get());
jtf.text_set("");
}
nom = 1;
}
}
private class ab implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (tn == 0) {
tn = Double.parseDouble(jtf.text_get());
jtf.text_set("");
} else {
tn2 = Double.parseDouble(jtf.text_get());
jtf.text_set("");
}
nom = 2;
}
}
private class Sub_But implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (tn == 0) {
tn = Double.parseDouble(jtf.text_get());
jtf.text_set("");
} else {
tn2 = Double.parseDouble(jtf.text_get());
jtf.text_set("");
}
nom = 3;
}
}
}
Solution
ANS:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Frame extends JFrame {
private double tn = 0;//here declare the variables
private double tn2 = 0;
private byte nom = -1;
private JTextField jtf;
public Frame() {
JButton[] bn = new JButton[10];
for ( int i = 9; i >= 0; i--) {
bn[i] = new JButton(Integer.toString(i));
}
//here declare the buttons
JButton eb= new JButton("e1");
JButton cb= new JButton("C");
JButton ab= new JButton("+");
JButton sb= new JButton("-");
JButton mb= new JButton("*");
JButton db= new JButton("/");
JButton ab= new JButton("+");
JButton sb= new JButton("-");
//here to set the size,bg,dimensionals
jtf = new JTextField();
jtf.setPreferredSize(new Dimension(180, 30));
jtf.setBackground(Color.BLUE);
jtf.setEnabled(false);
jtf.setHorizontalAlignment(4);
jtf.setDisabledTextColor(Color.GREEN);
//here set the layouts
JPanel PM = new JPanel();
PM.setLayout(new BoxLayout(PM, BoxLayout.Y_AXIS));
JPanel pt = new JPanel();
pt.setPreferredSize(new Dimension(160, 20));
pt.add(jtf);
JPanel pnb = new JPanel();
pnb.setPreferredSize(new Dimension(160, 100));
for(int i = 9; i>=0; i--) {
pnb.add(bn[i]);
}
//here buttons add to panels
JPanel pb_nom = new JPanel();
pb_nom.setPreferredSize(new Dimension(160, 35));
pb_nom.add(eb);
pb_nom.add(cb);
pb_nom.add(mb);
pb_nom.add(db);
pb_nom.add(ab);
pb_nom.add(sb);
umo_ji[] pb_action = new umo_ji[10];
for ( int i = 0; i < 10; i++ ) {
pb_action[i] = new umo_ji(bn[i]);
bn[i].addActionListener(pb_action[i]);
}
//here perform action buttons
eb e1 = new eb();
eb.addActionListener(e1);
cb c = new cb();
cb.addActionListener(c);
mb e2 = new mb();
mb.addActionListener(e2);
db e3 = new db();
db.addActionListener(e3);
ab add = new ab();
ab.addActionListener(add);
Sub_But subtract = new Sub_But();
sb.addActionListener(subtract);
PM.add(pt);
PM.add(pnb);
PM.add(pb_nom);
add(PM);
//To set the title and size
setTitle("Button_Test");
setSize(180, 290);
setLocationByPlatform(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
}
private class umo_ji implements ActionListener {
//here implements actionlistener
private String c;
public umo_ji(JButton a) {
this.c = a.text_get();
}
public void actionPerformed(ActionEvent e) {
if (!jtf.text_get().equals("0.0")) {
jtf.text_set(jtf.text_get() + c);
} else {
jtf.text_set("");
actionPerformed(e);
}
}
}
private class eb implements ActionListener {
@Override//overide buttons
public void actionPerformed(ActionEvent e) {
tn2 = Double.parseDouble(jtf.text_get());
if (nom == 0) {
jtf.text_set(Double.toString((Math.round((tn / tn2) * 100)) / 100));
} else if (nom == 1) {
jtf.text_set(Double.toString(tn * tn2));
} else if (nom == 2) {
jtf.text_set(Double.toString(tn2 + tn));
} else if (nom == 3) {
jtf.text_set(Double.toString(tn - tn2));
} else {
jtf.text_set(String.valueOf(tn));
}
tn = Double.parseDouble(jtf.text_get());
}
}
private class cb implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
jtf.text_set("");
tn = 0;
tn2 = 0;
nom = -1;
}
}
private class db implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (tn == 0) {
tn = Double.parseDouble(jtf.text_get());
jtf.text_set("");
} else {
tn2 = Double.parseDouble(jtf.text_get());
jtf.text_set("");
}
nom = 0;
}
}
private class mb implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (tn == 0) {
tn = Double.parseDouble(jtf.text_get());
jtf.text_set("");
} else {
tn2 = Double.parseDouble(jtf.text_get());
jtf.text_set("");
}
nom = 1;
}
}
private class ab implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (tn == 0) {
tn = Double.parseDouble(jtf.text_get());
jtf.text_set("");
} else {
tn2 = Double.parseDouble(jtf.text_get());
jtf.text_set("");
}
nom = 2;
}
}
private class Sub_But implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (tn == 0) {
tn = Double.parseDouble(jtf.text_get());
jtf.text_set("");
} else {
tn2 = Double.parseDouble(jtf.text_get());
jtf.text_set("");
}
nom = 3;
}
}
}

More Related Content

DOCX
culadora cientifica en java
TXT
New text document
DOCX
Ejemplo radio
DOCX
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
PDF
Hello, I need some assistance in writing a java program THAT MUST US.pdf
PDF
Calculator
PDF
Java programs
DOCX
Calculator code with scientific functions in java
culadora cientifica en java
New text document
Ejemplo radio
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
Hello, I need some assistance in writing a java program THAT MUST US.pdf
Calculator
Java programs
Calculator code with scientific functions in java

Similar to ANSimport javax.swing.;import java.awt.; import java.awt.ev.pdf (20)

DOCX
Exercícios Netbeans - Vera Cymbron
TXT
Maze
PDF
I have done it under neatbeans IDE and just added ToggleGroup for gr.pdf
PDF
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdf
PDF
Write a GUI application to simulate writing out a check. The value o.pdf
DOCX
Cambio de bases
PDF
In Java Write a GUI application to simulate writing out a check. The.pdf
PDF
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PPTX
Java calculator
DOC
PPT
DOCX
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
DOCX
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
TXT
Settings
PPT
PPTX
Net beansprojects
PPTX
Scientific calcultor-Java
PDF
I hope the below code is helpful to you, please give me rewards.im.pdf
PDF
Working with the Calculator program Once imported run the.pdf
PPTX
Java final project of scientific calcultor
Exercícios Netbeans - Vera Cymbron
Maze
I have done it under neatbeans IDE and just added ToggleGroup for gr.pdf
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
Cambio de bases
In Java Write a GUI application to simulate writing out a check. The.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
Java calculator
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
Settings
Net beansprojects
Scientific calcultor-Java
I hope the below code is helpful to you, please give me rewards.im.pdf
Working with the Calculator program Once imported run the.pdf
Java final project of scientific calcultor
Ad

More from anugrahafancy (20)

PDF
X has +2 charge It has low first and second ioniz.pdf
PDF
Valence Bond Theory According to valence band the.pdf
PDF
total volume =25+25=50 ml total millimoles of KI=.pdf
PDF
This type of deformation is irreversible. However.pdf
PDF
stereoisomers .pdf
PDF
Some elements receive their respective symbol bas.pdf
PDF
phosphonium ylide is produced when phosphonium ha.pdf
PDF
N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf
PDF
In chemistry, an amphoteric species is a molecule.pdf
PDF
Chemistry is the science of matter, especially it.pdf
PDF
Before this confederates began their general advance, General Lee pl.pdf
PDF
An understanding of periodic trends is important .pdf
PDF
Acid contains hydrogen ions. Thus, iodate will re.pdf
PDF
There is a difference between to connect to a network and to communi.pdf
PDF
The picture is not uploaded properly it is corrupted. please upload .pdf
PDF
No clarity in question . Not visibleSolutionNo clarity in ques.pdf
PDF
Date Account title Debit credit jan 30 cash 45000 common sto.pdf
PDF
Initial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdf
PDF
IntroductionDarwin argused that living organisms evolved from one .pdf
PDF
import java.awt.LinearGradientPaint; public class searchComparis.pdf
X has +2 charge It has low first and second ioniz.pdf
Valence Bond Theory According to valence band the.pdf
total volume =25+25=50 ml total millimoles of KI=.pdf
This type of deformation is irreversible. However.pdf
stereoisomers .pdf
Some elements receive their respective symbol bas.pdf
phosphonium ylide is produced when phosphonium ha.pdf
N1 V1 = N2 V2 50 x M1 = 1.50 x 2 x 17.7 M M1 = 1..pdf
In chemistry, an amphoteric species is a molecule.pdf
Chemistry is the science of matter, especially it.pdf
Before this confederates began their general advance, General Lee pl.pdf
An understanding of periodic trends is important .pdf
Acid contains hydrogen ions. Thus, iodate will re.pdf
There is a difference between to connect to a network and to communi.pdf
The picture is not uploaded properly it is corrupted. please upload .pdf
No clarity in question . Not visibleSolutionNo clarity in ques.pdf
Date Account title Debit credit jan 30 cash 45000 common sto.pdf
Initial Value=2.5Drift rate per annum=0.4Variance rate per annum.pdf
IntroductionDarwin argused that living organisms evolved from one .pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdf
Ad

Recently uploaded (20)

PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PPTX
Lesson notes of climatology university.
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Empowerment Technology for Senior High School Guide
PPTX
Introduction to Building Materials
PDF
Complications of Minimal Access Surgery at WLH
PDF
IGGE1 Understanding the Self1234567891011
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
1_English_Language_Set_2.pdf probationary
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
RMMM.pdf make it easy to upload and study
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Unit 4 Skeletal System.ppt.pptxopresentatiom
Lesson notes of climatology university.
What if we spent less time fighting change, and more time building what’s rig...
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Empowerment Technology for Senior High School Guide
Introduction to Building Materials
Complications of Minimal Access Surgery at WLH
IGGE1 Understanding the Self1234567891011
Digestion and Absorption of Carbohydrates, Proteina and Fats
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Indian roads congress 037 - 2012 Flexible pavement
Chinmaya Tiranga quiz Grand Finale.pdf
Final Presentation General Medicine 03-08-2024.pptx
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Supply Chain Operations Speaking Notes -ICLT Program
1_English_Language_Set_2.pdf probationary
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
RMMM.pdf make it easy to upload and study

ANSimport javax.swing.;import java.awt.; import java.awt.ev.pdf

  • 1. ANS: import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Frame extends JFrame { private double tn = 0;//here declare the variables private double tn2 = 0; private byte nom = -1; private JTextField jtf; public Frame() { JButton[] bn = new JButton[10]; for ( int i = 9; i >= 0; i--) { bn[i] = new JButton(Integer.toString(i)); } //here declare the buttons JButton eb= new JButton("e1"); JButton cb= new JButton("C"); JButton ab= new JButton("+"); JButton sb= new JButton("-"); JButton mb= new JButton("*"); JButton db= new JButton("/"); JButton ab= new JButton("+"); JButton sb= new JButton("-"); //here to set the size,bg,dimensionals jtf = new JTextField(); jtf.setPreferredSize(new Dimension(180, 30)); jtf.setBackground(Color.BLUE); jtf.setEnabled(false); jtf.setHorizontalAlignment(4); jtf.setDisabledTextColor(Color.GREEN); //here set the layouts JPanel PM = new JPanel(); PM.setLayout(new BoxLayout(PM, BoxLayout.Y_AXIS));
  • 2. JPanel pt = new JPanel(); pt.setPreferredSize(new Dimension(160, 20)); pt.add(jtf); JPanel pnb = new JPanel(); pnb.setPreferredSize(new Dimension(160, 100)); for(int i = 9; i>=0; i--) { pnb.add(bn[i]); } //here buttons add to panels JPanel pb_nom = new JPanel(); pb_nom.setPreferredSize(new Dimension(160, 35)); pb_nom.add(eb); pb_nom.add(cb); pb_nom.add(mb); pb_nom.add(db); pb_nom.add(ab); pb_nom.add(sb); umo_ji[] pb_action = new umo_ji[10]; for ( int i = 0; i < 10; i++ ) { pb_action[i] = new umo_ji(bn[i]); bn[i].addActionListener(pb_action[i]); } //here perform action buttons eb e1 = new eb(); eb.addActionListener(e1); cb c = new cb(); cb.addActionListener(c); mb e2 = new mb(); mb.addActionListener(e2); db e3 = new db(); db.addActionListener(e3); ab add = new ab(); ab.addActionListener(add); Sub_But subtract = new Sub_But(); sb.addActionListener(subtract); PM.add(pt);
  • 3. PM.add(pnb); PM.add(pb_nom); add(PM); //To set the title and size setTitle("Button_Test"); setSize(180, 290); setLocationByPlatform(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); } private class umo_ji implements ActionListener { //here implements actionlistener private String c; public umo_ji(JButton a) { this.c = a.text_get(); } public void actionPerformed(ActionEvent e) { if (!jtf.text_get().equals("0.0")) { jtf.text_set(jtf.text_get() + c); } else { jtf.text_set(""); actionPerformed(e); } } } private class eb implements ActionListener { @Override//overide buttons public void actionPerformed(ActionEvent e) { tn2 = Double.parseDouble(jtf.text_get()); if (nom == 0) { jtf.text_set(Double.toString((Math.round((tn / tn2) * 100)) / 100)); } else if (nom == 1) { jtf.text_set(Double.toString(tn * tn2)); } else if (nom == 2) { jtf.text_set(Double.toString(tn2 + tn)); } else if (nom == 3) {
  • 4. jtf.text_set(Double.toString(tn - tn2)); } else { jtf.text_set(String.valueOf(tn)); } tn = Double.parseDouble(jtf.text_get()); } } private class cb implements ActionListener { @Override public void actionPerformed(ActionEvent e) { jtf.text_set(""); tn = 0; tn2 = 0; nom = -1; } } private class db implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (tn == 0) { tn = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } else { tn2 = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } nom = 0; } } private class mb implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (tn == 0) { tn = Double.parseDouble(jtf.text_get());
  • 5. jtf.text_set(""); } else { tn2 = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } nom = 1; } } private class ab implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (tn == 0) { tn = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } else { tn2 = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } nom = 2; } } private class Sub_But implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (tn == 0) { tn = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } else { tn2 = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } nom = 3; } }
  • 6. } Solution ANS: import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Frame extends JFrame { private double tn = 0;//here declare the variables private double tn2 = 0; private byte nom = -1; private JTextField jtf; public Frame() { JButton[] bn = new JButton[10]; for ( int i = 9; i >= 0; i--) { bn[i] = new JButton(Integer.toString(i)); } //here declare the buttons JButton eb= new JButton("e1"); JButton cb= new JButton("C"); JButton ab= new JButton("+"); JButton sb= new JButton("-"); JButton mb= new JButton("*"); JButton db= new JButton("/"); JButton ab= new JButton("+"); JButton sb= new JButton("-"); //here to set the size,bg,dimensionals jtf = new JTextField(); jtf.setPreferredSize(new Dimension(180, 30)); jtf.setBackground(Color.BLUE); jtf.setEnabled(false); jtf.setHorizontalAlignment(4); jtf.setDisabledTextColor(Color.GREEN);
  • 7. //here set the layouts JPanel PM = new JPanel(); PM.setLayout(new BoxLayout(PM, BoxLayout.Y_AXIS)); JPanel pt = new JPanel(); pt.setPreferredSize(new Dimension(160, 20)); pt.add(jtf); JPanel pnb = new JPanel(); pnb.setPreferredSize(new Dimension(160, 100)); for(int i = 9; i>=0; i--) { pnb.add(bn[i]); } //here buttons add to panels JPanel pb_nom = new JPanel(); pb_nom.setPreferredSize(new Dimension(160, 35)); pb_nom.add(eb); pb_nom.add(cb); pb_nom.add(mb); pb_nom.add(db); pb_nom.add(ab); pb_nom.add(sb); umo_ji[] pb_action = new umo_ji[10]; for ( int i = 0; i < 10; i++ ) { pb_action[i] = new umo_ji(bn[i]); bn[i].addActionListener(pb_action[i]); } //here perform action buttons eb e1 = new eb(); eb.addActionListener(e1); cb c = new cb(); cb.addActionListener(c); mb e2 = new mb(); mb.addActionListener(e2); db e3 = new db(); db.addActionListener(e3); ab add = new ab(); ab.addActionListener(add);
  • 8. Sub_But subtract = new Sub_But(); sb.addActionListener(subtract); PM.add(pt); PM.add(pnb); PM.add(pb_nom); add(PM); //To set the title and size setTitle("Button_Test"); setSize(180, 290); setLocationByPlatform(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); } private class umo_ji implements ActionListener { //here implements actionlistener private String c; public umo_ji(JButton a) { this.c = a.text_get(); } public void actionPerformed(ActionEvent e) { if (!jtf.text_get().equals("0.0")) { jtf.text_set(jtf.text_get() + c); } else { jtf.text_set(""); actionPerformed(e); } } } private class eb implements ActionListener { @Override//overide buttons public void actionPerformed(ActionEvent e) { tn2 = Double.parseDouble(jtf.text_get()); if (nom == 0) { jtf.text_set(Double.toString((Math.round((tn / tn2) * 100)) / 100)); } else if (nom == 1) { jtf.text_set(Double.toString(tn * tn2));
  • 9. } else if (nom == 2) { jtf.text_set(Double.toString(tn2 + tn)); } else if (nom == 3) { jtf.text_set(Double.toString(tn - tn2)); } else { jtf.text_set(String.valueOf(tn)); } tn = Double.parseDouble(jtf.text_get()); } } private class cb implements ActionListener { @Override public void actionPerformed(ActionEvent e) { jtf.text_set(""); tn = 0; tn2 = 0; nom = -1; } } private class db implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (tn == 0) { tn = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } else { tn2 = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } nom = 0; } } private class mb implements ActionListener { @Override
  • 10. public void actionPerformed(ActionEvent e) { if (tn == 0) { tn = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } else { tn2 = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } nom = 1; } } private class ab implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (tn == 0) { tn = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } else { tn2 = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } nom = 2; } } private class Sub_But implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (tn == 0) { tn = Double.parseDouble(jtf.text_get()); jtf.text_set(""); } else { tn2 = Double.parseDouble(jtf.text_get()); jtf.text_set(""); }