evaluacion

3
package pruebas ; import java.awt.BorderLayout; import java.awt.Container; import java.awt.FlowLayout; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Clase extends JFrame{ public int n1, n2,x=0,y=1; public int mensaje; public JTextField texto1, texto2;; public JLabel resultado;; public Clase() { super("Suma Binaria"); setSize(400, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container cp = getContentPane();

Upload: jbersosa

Post on 14-Jul-2015

212 views

Category:

Healthcare


0 download

TRANSCRIPT

Page 1: Evaluacion

package pruebas ;

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.GridBagLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class Clase extends JFrame{

public int n1, n2,x=0,y=1;

public int mensaje;

public JTextField texto1, texto2;;

public JLabel resultado;;

public Clase() {

super("Suma Binaria");

setSize(400, 200);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container cp = getContentPane();

Page 2: Evaluacion

JPanel pediry = new JPanel();

JPanel a=new JPanel();

ButtonGroup bg= new ButtonGroup();

pediry.setLayout(new FlowLayout());

pediry.add(new JLabel("numero 1 "));

texto1=new JTextField(8);

pediry.add(texto1);

pediry.add(new JLabel("numero 2 "));

OyenteBoton oyenteboton=new OyenteBoton();

texto2=new JTextField(8);

pediry.add(texto2);

texto2.addActionListener(oyenteboton);

JRadioButton rb1=new JRadioButton("BINARIO");

JRadioButton rb2=new JRadioButton("OCTAL");

bg.add(rb1);

bg.add(rb2);

a.add(rb1);

a.add(rb2);

cp.add(pediry, BorderLayout.NORTH);

cp.add(a,BorderLayout.CENTER);

setVisible(true);

JButton boton;

JPanel pedirb = new JPanel();

Page 3: Evaluacion

GridBagLayout c= new GridBagLayout();

boton=new JButton("SUMAR");

boton.addActionListener(oyenteboton);

resultado=new JLabel();

pedirb.add(boton);

pedirb.add(resultado);

cp.add(pedirb, BorderLayout.SOUTH);

setVisible(true);

}

public class OyenteBoton implements ActionListener{

@Override

public void actionPerformed(ActionEvent e) {

n1=Integer.parseInt(texto1.getText());

n2=Integer.parseInt(texto2.getText());

mensaje=n1 +n2;

resultado.setText(String.valueOf(mensaje));

}

}

}