[PDF] /* PROGRAM TO IMPLEMENT SIMPLE CALCULATOR USING AWT





Previous PDF Next PDF



/* PROGRAM TO IMPLEMENT SIMPLE CALCULATOR USING AWT

PROGRAM TO IMPLEMENT SIMPLE CALCULATOR USING AWT*/ import java.awt.*; import java.awt.event.*; import java.applet.*;.



LAB MANUAL FOR PRACTICAL COURSES

PROGRAM import java.awt.*; import java.applet.*; import java.awt.event.*; To write a calculator program using java swing. ALGORITHM:.



Introduction to Programming Using Java

6.7.4 A Simple Calculator . Introduction to Programming Using Java is a free introductory computer programming ... AWT in most modern Java programs.



INTRODUCTION TO JAVA PROGRAMMING LECTURE NOTES B

GUI Programming with Java – AWT class hierarchy component



Chapter 4: Events GUI Components

https://mathcs.org/java/jbd/JBD%20-%20Chapter%2004.pdf



Introduction to GUI

by the application. • The panel in the Future Value Calculator interface contains ten ... The AWT classes are stored in the java.awt package while the.



SLIP 1 :

1) Write a java program to calculate area of rectangle by passing and 2) Design an AWT application to accept a number from user through textbox and ...



A Calculator Project

The Calculator class creates a UserInterface Class The buttons on the calculator are arranged in a 4x4 grid layout ... import java.awt.event.*;.



JAVA PROGRAMMING

Demonstrate an ability to design an object oriented system AWT B)Write a Java program compute factorial value using Applet.



L155 - JAVA PROGRAMMING LAB 1 a). Write a java program to

Write an applet program using Key events? 19 (a) Write a java program by using AWT components. (b) Write a java program to implement arithmetic calculator.

/* PROGRAM TO IMPLEMENT SIMPLE CALCULATOR USING AWT*/ 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(100);

GridLayout gl=new GridLayout(4,5);

setLayout(gl); for(int i=0;i<10;i++){ b[i]=new Button(""+i); add=new Button("+"); sub=new Button("-"); mul=new Button("*"); div=new Button("/"); mod=new Button("%"); clear=new Button("clear");

EQ=new Button("=");

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(); 1KNREDDYJAVA PROGRAMMING char ch=str.charAt(0); if (Character.isDigit(ch)) t1.setText(t1.getText()+str); else if(str.equals("+")) { v1=Integer.parseInt(t1.getText());

OP='+';

t1.setText(""); else if(str.equals("-")) { v1=Integer.parseInt(t1.getText());

OP='-';

t1.setText(""); else if(str.equals("*")) { v1=Integer.parseInt(t1.getText());

OP='*';

t1.setText(""); else if(str.equals("/")) { v1=Integer.parseInt(t1.getText());

OP='/';

t1.setText(""); else if(str.equals("%")){ v1=Integer.parseInt(t1.getText());

OP='%';

t1.setText(""); if(str.equals("=")){ 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("");

2KNREDDYJAVA PROGRAMMING

/*PROGRAM TO IMPLEMENT SIMPLE CALCULATOR USING SWING*/ import java.awt.*; import javax.swing.*; public class Calculator1 implements ActionListener{

JLabel jlab;

char OP;

JTextField t1;

int v1,v2; float result;

Calculator1( ) {

JButton b[]=new JButton[10];

JButton add,sub,mul,div,clear,mod,EQ;

JFrame jfrm = new JFrame("CALCULATOR");

jfrm.setSize(300, 180); jfrm.setLayout(new GridLayout(5,5)); t1=new JTextField(100); for(int i=0;i<10;i++) { b[i]=new JButton(""+i); add=new JButton("+"); sub=new JButton("-"); mul=new JButton("*"); div=new JButton("/"); mod=new JButton("%"); clear=new JButton("clear");

EQ=new JButton("=");

t1.addActionListener(this); 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);

jfrm.add(t1); for(int i=0;i<10;i++) { jfrm.add(b[i]); jfrm.add(add); jfrm.add(sub); jfrm.add(mul); jfrm.add(div); jfrm.add(mod); jfrm.add(clear); jfrm.add(EQ); jfrm.setVisible(true); public void actionPerformed(ActionEvent ae) {

String str=ae.getActionCommand();

char ch=str.charAt(0); if (Character.isDigit(ch)) t1.setText(t1.getText()+str); 3KNREDDYJAVA PROGRAMMING else if(str.equals("+")) { v1=Integer.parseInt(t1.getText());

OP='+';

t1.setText(""); else if(str.equals("-")){ v1=Integer.parseInt(t1.getText());

OP='-';

t1.setText(""); else if(str.equals("*")) { v1=Integer.parseInt(t1.getText());

OP='*';

t1.setText(""); else if(str.equals("/")){ v1=Integer.parseInt(t1.getText());

OP='/';

t1.setText(""); else if(str.equals("%")){ v1=Integer.parseInt(t1.getText());

OP='%';

t1.setText(""); if(str.equals("=")){ 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=(float)v1/v2; else if(OP=='%') result=v1%v2; t1.setText(""+result); if(str.equals("clear")) { t1.setText(""); public static void main(String[] args) {quotesdbs_dbs4.pdfusesText_7
[PDF] calculator program in java using class and objects

[PDF] calculator program in java using do while loop

[PDF] calculator program in java using if else

[PDF] calculator program in java using inheritance

[PDF] calculator program in java using switch case

[PDF] calculatrice matrice casio

[PDF] calculatrice matrice de passage

[PDF] calculatrice matrice determinant

[PDF] calculatrice matrice inverse

[PDF] calculatrice matrice inverse en ligne

[PDF] calculatrice matrice online

[PDF] calculatrice matrice valeur propre

[PDF] calculatrice numworks acheter

[PDF] calculatrice numworks emulateur

[PDF] calculatrice numworks jeu