CALCULADORA EN JAVA 2013


import java.awt.Color;
import java.awt.color.*;
import javax.swing.*;

import java.awt.event.*;

public class Formulario1 extends JFrame implements ActionListener{
    private JTextField textfield1,textfield2,textfield3;
    private JButton boton1,boton2,boton3,boton4,boton5;
    public Formulario1() {
  
   
    // CALCULADORA HECHA POR LUIS ANGEL RESTREPO//
    setLayout(null);
        textfield1=new JTextField();
        textfield1.setBounds(50,10,100,30);
        add(textfield1);
        textfield2=new JTextField();
        textfield2.setBounds(50,50,100,30);
        add(textfield2);
        textfield3=new JTextField();
        textfield3.setBounds(50,100,100,30);
        add(textfield3);
        
  
        
   
        
        boton1=new JButton("SUMAR");
        boton1.setBounds(30,150,80,80);
        boton1.setForeground(Color.BLACK);
        boton1.setBackground(Color.RED);
        add(boton1);
        boton1.addActionListener(this);
      
        
        boton2=new JButton("RESTAR");
        boton2.setBounds(120,150,80,80);
        add(boton2);
        boton2.addActionListener(this);
        boton2.setForeground(Color.BLACK);
        boton2.setBackground(Color.YELLOW);
        
        
        boton3=new JButton("MULTIPLICAR");
        boton3.setBounds(30,235,80,80);
        add(boton3);
        boton3.addActionListener(this);
        boton3.setForeground(Color.BLACK);
        boton3.setBackground(Color.YELLOW);
        
        
        boton4=new JButton("DIVIDIR");
        boton4.setBounds(120,235,80,80);
        add(boton4);
        boton4.addActionListener(this);
        boton4.setForeground(Color.BLACK);
        boton4.setBackground(Color.RED);
        
        
        
        boton5=new JButton("BORRAR");
        boton5.setBounds(30,360,180,80);
        add(boton5);
        boton5.addActionListener(this);
        boton5.setForeground(Color.RED);
        boton5.setBackground(Color.BLACK);
        
    
        
    }
    
    public void actionPerformed(ActionEvent e) {
        if (e.getSource()==boton1 ) {
            String cad1=textfield1.getText();
            String cad2=textfield2.getText();
            int x1=Integer.parseInt(cad1);
            int x2=Integer.parseInt(cad2);
            int suma=x1+x2;
            String total=String.valueOf(suma);
            textfield3.setText(total);           
        }
         
          if (e.getSource()==boton3 ) {
            String cad3=textfield1.getText();
            String cad4=textfield2.getText();
            int x3=Integer.parseInt(cad3);
            int x4=Integer.parseInt(cad4);
            int multiplicar=x3*x4;
            String resul=String.valueOf(multiplicar);
            textfield3.setText(resul); 
            
          }
            
              if (e.getSource()==boton4 ) {
                String cad3=textfield1.getText();
                String cad4=textfield2.getText();
                int x3=Integer.parseInt(cad3);
                int x4=Integer.parseInt(cad4);
                int dividir=x3/x4;
                String resul=String.valueOf(dividir);
                textfield3.setText(resul); 
                
              }
               
              if (e.getSource()==boton2 ) {
                    String cad3=textfield1.getText();
                    String cad4=textfield2.getText();
                    int x3=Integer.parseInt(cad3);
                    int x4=Integer.parseInt(cad4);
                    int restar=x3-x4;
                    String resul=String.valueOf(restar);
                    textfield3.setText(resul); 
                
        }else if( e.getSource()==boton5){
        textfield1.setText(null);
        textfield2.setText(null);
        textfield3.setText(null);
        }
    }
    
    public static void main(String[] ar) {
    
    Formulario1 formulario=new Formulario1();
        formulario.setBounds(200,50,400,500);
        formulario.setVisible(true);
    
    }

Comentarios

  1. Tioga Steel Countertops - TITaniumArt
    TINY STEVE, Inc. ceramic or titanium flat iron The titanium nipple bars TINY STEVE is the finest sugarboo extra long digital titanium styler quality steel titanium grey countertops with a chrome finish for corrosion ford edge titanium 2021 resistant glass products.

    ResponderEliminar

Publicar un comentario

Entradas populares