elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  operaciones aritmeticas en JAVA ECLIPSE
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: operaciones aritmeticas en JAVA ECLIPSE  (Leído 6,801 veces)
leliCabello

Desconectado Desconectado

Mensajes: 158


Ver Perfil
operaciones aritmeticas en JAVA ECLIPSE
« en: 12 Octubre 2009, 02:47 am »

Hola...Porfavor ayudenme con esto, al escribir 2 numeros y hacer clic en sumar, tiene que salir la respuesta, al igual para restar, dividir y multiplicar....pero no me sale :-(...AYUDENMEEEE PLEASE....aqui les dejo mi avance
Código:
package prueba;
import javax.swing.*;

public class oper extends JFrame{
public oper(){
super();
}
private static final long serialVersionUID = 1L;
JPanel panel = new JPanel();
JLabel label = new JLabel("Ingresar primer número");
JTextField texto = new JTextField(10);
JLabel label2 = new JLabel("Ingresar segundo número");
JTextField texto2 = new JTextField(10);
JButton boton = new JButton ("Sumar");
JButton boton2 = new JButton ("Restar");
JButton boton3 = new JButton ("Multiplicar");
JButton boton4 = new JButton ("Dividir");
public void mipanel(){
add(panel);
panel.add(label);
panel.add(texto);
panel.add(label2);
panel.add(texto2);
panel.add(boton);
panel.add(boton2);
panel.add(boton3);
panel.add(boton4);
super.setTitle("Operaciones Aritméticas");
super.setVisible(true);
super.setSize(300, 170);

OyenteExternoAccion oyenteBotonUno = new OyenteExternoAccion(texto,texto2);
boton.addActionListener(oyenteBotonUno);

}
public static void main(String[] args) {
oper obj=new oper();
obj.mipanel();

}

}

Código:
package prueba;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;


public class OyenteExternoAccion implements ActionListener{
String x;
String y;
int num1;
int num2;
int suma;
private JTextField texto;
private JTextField texto2;

public OyenteExternoAccion (JTextField texto, JTextField texto2)
{
this.texto = texto;
this.texto2 = texto2;

}

@Override
public void actionPerformed(ActionEvent evento) {
JButton boton=(JButton) evento.getSource();
x=texto.getText();
y=texto2.getText();
num1=Integer.parseInt(x);
num2=Integer.parseInt(y);
if (x.equals(num1)&& y.equals(num2)){
suma = suma + num1;}


}

}


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[JAVA] NEW Operaciones con quebrados ~ ver.2
Java
Dnk! 4 6,856 Último mensaje 15 Diciembre 2010, 18:04 pm
por Dnk!
necesito por favor que me ayuden con el algoritmo en JAVA ECLIPSE indigo
Java
georgesf13 5 5,568 Último mensaje 2 Noviembre 2011, 05:00 am
por bengy
Movimiento imagenes en Java- Eclipse
Java
cris26 3 7,396 Último mensaje 5 Mayo 2012, 17:15 pm
por lluvplay
Operaciones aritmeticas de una ristra con recursividad
Java
Javator 4 3,360 Último mensaje 25 Marzo 2014, 23:22 pm
por 1mpuls0
Operaciones aritmeticas variables bash
Scripting
rusogumo 2 3,275 Último mensaje 12 Marzo 2015, 12:17 pm
por Eleкtro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines