You are on page 1of 3

ARITMETICA

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ARITMETICA extends JFrame 
{
    public JLabel T1,T2,T_RES;
    public JTextField N1,N2,RES;
    public JButton SUMAR,RESTAR,PROD,DIV,INV;
 
    public ARITMETICA(){//
        super("ARITMETICA EN JAVA");//Titulo
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(510,460);
 
        T1 = new JLabel("PRIMER NUMERO  ");
        T2 = new JLabel("SEGUNDO NUMERO ");
        T_RES = new JLabel("RESULTADO");
 
        N1 = new JTextField(10);
        N2 = new JTextField(10);
        RES = new JTextField(10);
        RES.setEditable(false);//define el texfiel de solo lectura
 
        SUMAR = new JButton("SUMAR");
        RESTAR = new JButton("RESTAR");
        PROD = new JButton("MULTIPLICAR");
        DIV = new JButton("DIVIDIR");
        INV =new JButton("INVERTIR");
        //FlowLayout DISTRIBUIDOR = new FlowLayout();
        //this.setLayout(DISTRIBUIDOR);
 
        add(T1);T1.setBounds(50,80,130,30);//permite colocar en el frame los 
objetos
        add(N1);N1.setBounds(200,80,100,30);//el setbounds permite identiicar 
la columna y la fila para ubicar el objeto en el lugar que uno desea
        add(T2);T2.setBounds(50,150,150,30);//(col,fila,ancho,alto)
        add(N2);N2.setBounds(200,150,100,30);
        add(T_RES);T_RES.setBounds(50,250,150,30);
        add(RES);RES.setBounds(200,250,100,30);
        add(SUMAR);SUMAR.setBounds(50,300,100,30);
        add(RESTAR);RESTAR.setBounds(180,300,100,30);
        add(PROD);PROD.setBounds(300,300,115,30);
        add(DIV);DIV.setBounds(350,100,115,30);
        add(INV);INV.setBounds(250,350,115,30);       
    
 
    SUMAR.addActionListener( new ActionListener(){
    public void  actionPerformed(ActionEvent EVENTO)
    {
        float NUM1,NUM2,T_RESULT;
        try//controla el codigo a ejecutar
        {
Página 1
ARITMETICA
            NUM1= Float.parseFloat(N1.getText());
            NUM2= Float.parseFloat(N2.getText());
            T_RESULT= NUM1 + NUM2;
 
            RES.setText(String.valueOf(T_RESULT));
             T_RES.setText("LA SUMA ES");
        }
        catch(Exception E)//muestra el codigo solo si el otro codigo tiene 
error
        {
            T_RES.setText("ERROR AL SUMAR");
        }
    }
    }
    );
    
    RESTAR.addActionListener( new ActionListener(){
    public void  actionPerformed(ActionEvent EVENTO)
    {
        float NUM1,NUM2,T_RESULT;
        try
        {
            NUM1= Float.parseFloat(N1.getText());
            NUM2= Float.parseFloat(N2.getText());
            T_RESULT= NUM1 ‐ NUM2;
 
            RES.setText(String.valueOf(T_RESULT));
             T_RES.setText("LA RESTA ES");
        }
        catch(Exception E)
        {
            T_RES.setText("ERROR AL RESTAR");
        }
    }
    }
    );
    PROD.addActionListener( new ActionListener(){
    public void  actionPerformed(ActionEvent EVENTO)
    {
        float NUM1,NUM2,T_RESULT;
        try
        {
            NUM1= Float.parseFloat(N1.getText());
            NUM2= Float.parseFloat(N2.getText());
            T_RESULT= NUM1 * NUM2;
 
            RES.setText(String.valueOf(T_RESULT));
             T_RES.setText("EL PRODUCTO ES");
        }
        catch(Exception E)
        {
            T_RES.setText("ERROR AL RESTAR");
Página 2
ARITMETICA
        }
    }
    }
    );
    DIV.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent e){
     float a,b,c;
     a=Float.parseFloat(N1.getText());
     b=Float.parseFloat(N2.getText());
     c=a/b;
     RES.setText(""+c);
     T_RES.setText("LA DIVISION ES = ");
     }
    }
    );
    INV.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent e){
     String cad,res="";
     cad=N1.getText();
     for(int i=cad.length();i>=0;i‐‐){
        res=res+cad.charAt(i);
     }
     RES.setText(""+res);
     T_RES.setText("EL INVERTIDO ES");
     }
    }
    
     );
  }
  public static void main(String[] ARGUMENTOS)
  {
        ARITMETICA MI_INTERFAZ = new ARITMETICA();
        //MI_INTERFAZ.setResizable(true);
        MI_INTERFAZ.setLayout(null);//el set layout null habilita el posecionar
los objets el frame (setbounds)
        MI_INTERFAZ.setVisible(true);
  }
}
//practica  esCRIBIR UNA APLICACION EN MODO GAFICO UE PERMITE INGRESAR UN 
NUMERO Y QUE REALIZE LAS SIGUIENTES ACCIONES INVERTIR UN NUMERO ,CONTAR DIGITOS
//diGITOS PARES E IMPARES, SUMAR LOS DIGITOS,MULTIPICAR LOS DIGITOS SIN 
CONSIDERAR EL CERO, 
//ESCRIBRI OTRA APLICACION PARA FIBO,1 2 4 7 11 16::1 2 6 24 120,
//alMACENAR EN DOS VECTORES NUMEROS ENTEROS Y SUMAR AMBOS VECTORES EN UN TERCER
VECTOR Y MOSTRAR LOS RESOLTADOS.

Página 3

You might also like

  • Circulo
    Circulo
    Document12 pages
    Circulo
    crbv177
    No ratings yet
  • Calcien
    Calcien
    Document4 pages
    Calcien
    crbv177
    No ratings yet
  • Prog 3
    Prog 3
    Document7 pages
    Prog 3
    crbv177
    No ratings yet
  • Prog1 PDF
    Prog1 PDF
    Document5 pages
    Prog1 PDF
    crbv177
    No ratings yet
  • Prog 10
    Prog 10
    Document7 pages
    Prog 10
    crbv177
    No ratings yet
  • Prog 7
    Prog 7
    Document4 pages
    Prog 7
    crbv177
    No ratings yet
  • Prog 3
    Prog 3
    Document7 pages
    Prog 3
    crbv177
    No ratings yet
  • Raton
    Raton
    Document2 pages
    Raton
    crbv177
    No ratings yet
  • Prog 3
    Prog 3
    Document7 pages
    Prog 3
    crbv177
    No ratings yet
  • Prog 1
    Prog 1
    Document5 pages
    Prog 1
    crbv177
    No ratings yet
  • Poligono
    Poligono
    Document5 pages
    Poligono
    crbv177
    No ratings yet
  • Prog2 PDF
    Prog2 PDF
    Document1 page
    Prog2 PDF
    crbv177
    No ratings yet
  • Prog 3
    Prog 3
    Document7 pages
    Prog 3
    crbv177
    No ratings yet
  • Dibujado
    Dibujado
    Document3 pages
    Dibujado
    crbv177
    No ratings yet
  • Parte
    Parte
    Document2 pages
    Parte
    crbv177
    No ratings yet
  • Principio Main
    Principio Main
    Document1 page
    Principio Main
    crbv177
    No ratings yet
  • Plantilla Ejer 1110
    Plantilla Ejer 1110
    Document3 pages
    Plantilla Ejer 1110
    crbv177
    No ratings yet
  • Fuerzas Conservativas
    Fuerzas Conservativas
    Document2 pages
    Fuerzas Conservativas
    crbv177
    No ratings yet
  • Laboratorio V
    Laboratorio V
    Document1 page
    Laboratorio V
    crbv177
    No ratings yet
  • Prog Java
    Prog Java
    Document1 page
    Prog Java
    crbv177
    No ratings yet
  • Archivos Complet
    Archivos Complet
    Document4 pages
    Archivos Complet
    crbv177
    No ratings yet
  • Player
    Player
    Document56 pages
    Player
    crbv177
    No ratings yet
  • Practica 3
    Practica 3
    Document7 pages
    Practica 3
    crbv177
    No ratings yet
  • Conversion Es
    Conversion Es
    Document8 pages
    Conversion Es
    crbv177
    No ratings yet
  • Práctica Examen
    Práctica Examen
    Document3 pages
    Práctica Examen
    crbv177
    No ratings yet
  • Laboratorio Vi
    Laboratorio Vi
    Document1 page
    Laboratorio Vi
    crbv177
    No ratings yet
  • Sesion7 C
    Sesion7 C
    Document5 pages
    Sesion7 C
    crbv177
    No ratings yet
  • Guia 2017
    Guia 2017
    Document182 pages
    Guia 2017
    crbv177
    100% (1)
  • Laboratorio V
    Laboratorio V
    Document1 page
    Laboratorio V
    crbv177
    No ratings yet