0% found this document useful (0 votes)
5 views5 pages

Java Applet for Basic Math Operations

This document summarizes a Java program that allows a user to enter integer numbers and perform the four basic math operations of addition, subtraction, multiplication, and division. The program was written by Ricardo Damacela for his second year of electromechanical engineering studies. It uses applets, buttons, text fields, and events to display the numbers input and calculation results.

Uploaded by

Ricardo Damacela
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Java Applet for Basic Math Operations

This document summarizes a Java program that allows a user to enter integer numbers and perform the four basic math operations of addition, subtraction, multiplication, and division. The program was written by Ricardo Damacela for his second year of electromechanical engineering studies. It uses applets, buttons, text fields, and events to display the numbers input and calculation results.

Uploaded by

Ricardo Damacela
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAMACION ll

CARRERA: ELECTROMECNICA NIVEL: SEGUNDO NOMBRE: RICARDO DAMACELA FECHA: 05-juno - 2012

Realizar un programa que permita ingresar nmeros enteros, y realizar las 4 operaciones bsicas.

CODIFICACIN EN JAVA import [Link].*; import [Link].*; import [Link].*; public class Resta extends Applet { ArcControls controls; // Objeto para manejar botones, cuadros de textos ArcCanvas canvas; // Objeto para redibujar public void init() { setLayout(new BorderLayout()); canvas = new ArcCanvas(); add("Center", canvas); add("South", controls = new ArcControls(canvas)); } public void destroy() { remove(controls); remove(canvas); } public void start() { [Link](true); } public void stop() { [Link](false); } public void processEvent(AWTEvent e) {

if ([Link]() == Event.WINDOW_DESTROY) { [Link](0); } } public static void main(String args[]) { Frame f = new Frame("Suma de dos numeros"); Datos datos = new Datos(); [Link](); [Link](); [Link]("Center", datos); [Link](600, 200); [Link](); } class ArcCanvas extends Canvas { int numero1; int numero2; int respuesta; Font font = new [Link]("SansSerif", [Link], 12); public void paint(Graphics g) { int sx=10; int sy=10; [Link]("Numero1 = " + numero1, sx, sy); [Link]("Numero2 = " + numero2, sx, sy + 14); [Link]("Respuesta = " + respuesta, sx, sy + 28); } public void redraw(int n1, int n2, int r) { this.numero1 = n1; this.numero2 = n2; [Link] = r; repaint(); } } class ArcControls extends Panel implements ActionListener { TextField num1; TextField num2; TextField resp;

ArcCanvas canvas; public ArcControls(ArcCanvas canvas) { Button b = null; Button c= null; Button d = null; Button e= null; [Link] = canvas; add(num1 = new TextField("", 4)); add(num2 = new TextField("", 4)); add(resp = new TextField("",4)); b = new Button("Sumar"); [Link](this); c = new Button("Restar"); [Link](this); d = new Button("Multiplicar"); [Link](this); e = new Button("Dividir"); [Link](this);

add(b); add(c); add(d); add(e); } public void actionPerformed(ActionEvent ev) { String label = [Link](); int n1; int n2; int res=0; [Link]("" + label); n1 = [Link]([Link]().trim()); n2 = [Link]([Link]().trim()); if (label== "Sumar") res = n1 + n2; else if (label== "Restar") res = n1 - n2; else if (label=="Multiplicar") res = n1 * n2; else if (label=="Dividir") res = n1 / n2; String re = ""+res; [Link](re);

[Link](n1, n2, res); } } CODIFICACIN EN HTML


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body bgcolor="000000"> <center> <applet code = "[Link]" width = "500" height = "300" > </applet> </center> </body> </html>

PROGRAMA CORRIDO EN JAVA

PROGRAMA CORRIDO EN INTERNET EXPLORER

You might also like