0% found this document useful (0 votes)
22 views11 pages

HOJA TÉCNICA No ../I-2020

This document contains the code for a Java GUI calculator application created by the student. It includes: - The code for the interface containing buttons for numbers 0-9, basic math operators, a clear button, and a result button. - Code to initialize the interface components when the form is created and add action listeners to each button. - Variables to store the numbers entered and calculation results. The student submitted this code as their solution to a programming assignment to create a basic calculator interface and logic.
Copyright
© © All Rights Reserved
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)
22 views11 pages

HOJA TÉCNICA No ../I-2020

This document contains the code for a Java GUI calculator application created by the student. It includes: - The code for the interface containing buttons for numbers 0-9, basic math operators, a clear button, and a result button. - Code to initialize the interface components when the form is created and add action listeners to each button. - Variables to store the numbers entered and calculation results. The student submitted this code as their solution to a programming assignment to create a basic calculator interface and logic.
Copyright
© © All Rights Reserved
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
You are on page 1/ 11

UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III

FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

HOJA TÉCNICA No……../I-2020

Para: Vidher W. Bustillos D.


DOCENTE DE LA MATERIA DE LAB. MEC-236

De: ……………humerez pairumani jhonny……………….………………………………


Estudiantes del:………………….…semestre de la carrera:…
3er…………………….

Referencia: ……………………(Titulo)…gui…………………………………

Fecha de entrega:……
28/05/2020………………………………………………………………………..
Señor docente:
Una vez realizado y culminado la práctica No…….referido a:…………………….………….......
Presento ante Ud. La codificación de los programas asignados:

Programa No1:……………….Titulo……gui…………………….

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package calculadora.oficial;

/**
*
* @author JHONNY HUMEREZ
*/
public class Interfaz extends javax.swing.JFrame {

/**
* Creates new form Interfaz
*/
public Interfaz() {
initComponents();
}
String numero1="";//variable vacia
String numero2="";
int contador=0;

/**
* This method is called from within the constructor to initialize the form.

Página 1 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

num2 = new javax.swing.JButton();


num3 = new javax.swing.JButton();
num1 = new javax.swing.JButton();
num5 = new javax.swing.JButton();
num6 = new javax.swing.JButton();
num4 = new javax.swing.JButton();
num8 = new javax.swing.JButton();
num9 = new javax.swing.JButton();
num7 = new javax.swing.JButton();
num0 = new javax.swing.JButton();
borrar = new javax.swing.JButton();
punto = new javax.swing.JButton();
resultado = new javax.swing.JButton();
porc = new javax.swing.JButton();
prom = new javax.swing.JButton();
div = new javax.swing.JButton();
mul = new javax.swing.JButton();
etiqueta2 = new javax.swing.JLabel();
etiqueta3 = new javax.swing.JLabel();
etiqueta1 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

num2.setText("2");
num2.setMargin(new java.awt.Insets(2, 2, 2, 2));
num2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num2ActionPerformed(evt);
}
});
getContentPane().add(num2, new org.netbeans.lib.awtextra.AbsoluteConstraints(108,
39, 65, 65));

num3.setText("3");
num3.setMargin(new java.awt.Insets(2, 2, 2, 2));
num3.addActionListener(new java.awt.event.ActionListener() {

Página 2 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

public void actionPerformed(java.awt.event.ActionEvent evt) {


num3ActionPerformed(evt);
}
});
getContentPane().add(num3, new org.netbeans.lib.awtextra.AbsoluteConstraints(180,
39, 65, 65));

num1.setText("1");
num1.setMargin(new java.awt.Insets(2, 2, 2, 2));
num1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num1ActionPerformed(evt);
}
});
getContentPane().add(num1, new org.netbeans.lib.awtextra.AbsoluteConstraints(36,
39, 65, 65));

num5.setText("5");
num5.setMargin(new java.awt.Insets(2, 2, 2, 2));
num5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num5ActionPerformed(evt);
}
});
getContentPane().add(num5, new org.netbeans.lib.awtextra.AbsoluteConstraints(108,
117, 65, 65));

num6.setText("6");
num6.setMargin(new java.awt.Insets(2, 2, 2, 2));
num6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num6ActionPerformed(evt);
}
});
getContentPane().add(num6, new org.netbeans.lib.awtextra.AbsoluteConstraints(180,
117, 65, 65));

num4.setText("4");
num4.setMargin(new java.awt.Insets(2, 2, 2, 2));
num4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num4ActionPerformed(evt);
}
});

Página 3 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

getContentPane().add(num4, new org.netbeans.lib.awtextra.AbsoluteConstraints(36,


117, 65, 65));

num8.setText("8");
num8.setMargin(new java.awt.Insets(2, 2, 2, 2));
num8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num8ActionPerformed(evt);
}
});
getContentPane().add(num8, new org.netbeans.lib.awtextra.AbsoluteConstraints(108,
195, 65, 65));

num9.setText("9");
num9.setMargin(new java.awt.Insets(2, 2, 2, 2));
num9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num9ActionPerformed(evt);
}
});
getContentPane().add(num9, new org.netbeans.lib.awtextra.AbsoluteConstraints(180,
195, 65, 65));

num7.setText("7");
num7.setMargin(new java.awt.Insets(2, 2, 2, 2));
num7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num7ActionPerformed(evt);
}
});
getContentPane().add(num7, new org.netbeans.lib.awtextra.AbsoluteConstraints(36,
195, 65, 65));

num0.setText("0");
num0.setMargin(new java.awt.Insets(2, 2, 2, 2));
num0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num0ActionPerformed(evt);
}
});
getContentPane().add(num0, new org.netbeans.lib.awtextra.AbsoluteConstraints(108,
278, 65, 65));

borrar.setText("C");
borrar.setMargin(new java.awt.Insets(2, 2, 2, 2));

Página 4 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

borrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
borrarActionPerformed(evt);
}
});
getContentPane().add(borrar, new org.netbeans.lib.awtextra.AbsoluteConstraints(180,
278, 65, 65));

punto.setText(".");
punto.setMargin(new java.awt.Insets(2, 2, 2, 2));
punto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
puntoActionPerformed(evt);
}
});
getContentPane().add(punto, new org.netbeans.lib.awtextra.AbsoluteConstraints(36,
278, 65, 65));

resultado.setText("=");
resultado.setMargin(new java.awt.Insets(2, 2, 2, 2));
resultado.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resultadoActionPerformed(evt);
}
});
getContentPane().add(resultado, new
org.netbeans.lib.awtextra.AbsoluteConstraints(380, 130, 65, 65));

porc.setText("porcentaje");
porc.setMargin(new java.awt.Insets(2, 2, 2, 2));
porc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
porcActionPerformed(evt);
}
});
getContentPane().add(porc, new org.netbeans.lib.awtextra.AbsoluteConstraints(450,
130, 65, 65));

prom.setText("prome");
prom.setMargin(new java.awt.Insets(2, 2, 2, 2));
prom.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
promActionPerformed(evt);
}
});

Página 5 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

getContentPane().add(prom, new org.netbeans.lib.awtextra.AbsoluteConstraints(300,


130, 65, 65));

div.setText("/");
div.setMargin(new java.awt.Insets(2, 2, 2, 2));
div.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
divActionPerformed(evt);
}
});
getContentPane().add(div, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 210,
65, 65));

mul.setText("*");
mul.setMargin(new java.awt.Insets(2, 2, 2, 2));
mul.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mulActionPerformed(evt);
}
});
getContentPane().add(mul, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 60,
65, 65));

etiqueta2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
getContentPane().add(etiqueta2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(540, 120, 230, 40));

etiqueta3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
getContentPane().add(etiqueta3, new
org.netbeans.lib.awtextra.AbsoluteConstraints(540, 240, 230, 40));

etiqueta1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
getContentPane().add(etiqueta1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(540, 70, 230, 30));

jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0,
0)));
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(540,
0, 230, 390));

pack();
}// </editor-fold>

private void resultadoActionPerformed(java.awt.event.ActionEvent evt) {


if(!etiqueta3.getText().equals("")||contador != 0){

Página 6 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

operaciones();
etiqueta2.setText("");
}
}

private void num1ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "1";
etiqueta3.setText(numero1);
}

private void num2ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "2";
etiqueta3.setText(numero1);
}

private void num3ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "3";
etiqueta3.setText(numero1);
}

private void num4ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "4";
etiqueta3.setText(numero1);
}

private void num5ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "5";
etiqueta3.setText(numero1);
}

private void num6ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "6";
etiqueta3.setText(numero1);
}

private void num7ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "7";
etiqueta3.setText(numero1);
}

private void num8ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "8";
etiqueta3.setText(numero1);
}

Página 7 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

private void num9ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "9";
etiqueta3.setText(numero1);
}

private void puntoActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += ".";
etiqueta3.setText(numero1);
}

private void num0ActionPerformed(java.awt.event.ActionEvent evt) {


numero1 += "0";
etiqueta3.setText(numero1);
}

private void borrarActionPerformed(java.awt.event.ActionEvent evt) {


numero1 = "";
numero2 = "";
etiqueta1.setText("");
etiqueta2.setText("");
etiqueta3.setText("");
contador = 0;//para numeros,o,.,c
}

private void mulActionPerformed(java.awt.event.ActionEvent evt) {


if(!etiqueta3.getText().equals("")||contador != 0){
operaciones();
etiqueta2.setText("*");
}
}

private void divActionPerformed(java.awt.event.ActionEvent evt) {


if(!etiqueta3.getText().equals("")||contador != 0){
operaciones();
etiqueta2.setText("/");
}
}

private void promActionPerformed(java.awt.event.ActionEvent evt) {


if(!etiqueta3.getText().equals("")||contador != 0){
operaciones();
etiqueta2.setText("prome");
}
}

Página 8 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

private void porcActionPerformed(java.awt.event.ActionEvent evt) {


if(!etiqueta3.getText().equals("")||contador != 0){
operaciones();
etiqueta2.setText("porcentaje");
}
}
void operaciones(){
double n1,n2;
if(!etiqueta3.getText().equals("")){
if(contador==0){
numero2=numero1;
etiqueta2.setText(numero2);
}
if(numero2.equals("")){
numero2 = "0";
}
n1 = Double.valueOf(numero2);
n2 = Double.valueOf(numero1);
if(etiqueta2.getText().equals("*")){
numero2 = String.valueOf(n1*n2);
}
if(etiqueta2.getText().equals("/")){
numero2 = String.valueOf(n1/n2);
}
if(etiqueta2.getText().equals("prome")){
numero2 = String.valueOf((n1 + n2)/2);
}
if(etiqueta2.getText().equals("porcentaje")){
numero2 = String.valueOf((n1*100)/(n1+n2));
}
etiqueta3.setText("");
numero1 = "";
contador++;
etiqueta1.setText(numero2);

}
/**e
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

Página 9 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and
feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Interfaz().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton borrar;
private javax.swing.JButton div;
private javax.swing.JLabel etiqueta1;
private javax.swing.JLabel etiqueta2;
private javax.swing.JLabel etiqueta3;
private javax.swing.JLabel jLabel1;
private javax.swing.JButton mul;
private javax.swing.JButton num0;

Página 10 de 11
UNIVERSIDAD MAYOR DE SAN ANDRÉS LMEC-236 MÉTODOS NUMÉRICOS Y ALGORITMOS III
FACULTAD DE INGENIERÍA Ing. Vidher W. Bustillos D.

private javax.swing.JButton num1;


private javax.swing.JButton num2;
private javax.swing.JButton num3;
private javax.swing.JButton num4;
private javax.swing.JButton num5;
private javax.swing.JButton num6;
private javax.swing.JButton num7;
private javax.swing.JButton num8;
private javax.swing.JButton num9;
private javax.swing.JButton porc;
private javax.swing.JButton prom;
private javax.swing.JButton punto;
private javax.swing.JButton resultado;
// End of variables declaration
}

Funcionamiento:graficas

Programa No2:……………….Titulo………………………….

Funcionamiento:

firma

Estudiante:……………………
C.I…………………

Página 11 de 11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy