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

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  code JRadioButton problema al seleccionar 2 JRadioButton
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: code JRadioButton problema al seleccionar 2 JRadioButton  (Leído 2,245 veces)
rub'n


Desconectado Desconectado

Mensajes: 1.217


(e -> λ("live now")); tatuar -> λ("α");


Ver Perfil WWW
code JRadioButton problema al seleccionar 2 JRadioButton
« en: 7 Enero 2012, 02:36 am »

osea la cuestion es que introdusco 2 numeros en sus JTextField y luego escojo si sumar o restar y presiono resultado , suma y resta correctamente.

pero como hago para seleccionar solo un JRadioButton , al presionar sumar y luego presionar restar se quedan los 2 presionados.  :(

soy novatooo  ;D ;D ;D
 
Código
  1. import javax.swing.*;
  2. import javax.swing.event.*;
  3. import java.awt.event.*;
  4. public class RadioBoton24 extends JFrame implements ActionListener{
  5.  
  6. private JTextField leerNum1,leerNum2;
  7. private JButton resultado;
  8. private JRadioButton sumar,restar;
  9. private ButtonGroup grupo;
  10.  
  11. public RadioBoton24() {
  12.  
  13. setLayout(null);
  14. leerNum1 = new JTextField("numero 1");
  15. leerNum1.setBounds(60,30,75,25);
  16. add(leerNum1);
  17.  
  18. leerNum2 = new JTextField("numero 2");
  19. leerNum2.setBounds(60,60,75,25);
  20. add(leerNum2);
  21. leerNum2.addActionListener(this);
  22.  
  23. sumar = new JRadioButton("Sumar");
  24. sumar.setBounds(35,90,80,30);
  25. add(sumar);
  26.  
  27. restar = new JRadioButton("Restar");
  28. restar.setBounds(130,90,80,30);
  29. add(restar);
  30.  
  31. resultado = new JButton("Calcular");
  32. resultado.setBounds(50,135,90,25);
  33. add(resultado);
  34. resultado.addActionListener(this);
  35.  
  36. grupo = new ButtonGroup();
  37.  
  38. add(sumar);  // editar error aquí. solución por leyer.
  39. add(restar);
  40. }
  41.  
  42. public void actionPerformed(ActionEvent e) {
  43.  
  44. if(e.getSource() == resultado) {
  45. int num1 = Integer.parseInt(leerNum1.getText());
  46. int num2 = Integer.parseInt(leerNum2.getText());
  47. int resultado = 0;
  48. if(sumar.isSelected()) {
  49. resultado = num1+num2;
  50. setTitle("la Suma es: "+resultado);
  51. }
  52. if(restar.isSelected()) {
  53. resultado = num1 - num2;
  54. setTitle("la Resta es: "+resultado);
  55. }
  56. //setTitle("el resultado es: "+String.valueOf(resultado));
  57. }
  58. }
  59.  
  60. public static void main(String[] args) {
  61.  
  62. RadioBoton24 o = new RadioBoton24();
  63. o.setBounds(20,20,450,250);
  64. o.setVisible(true);
  65. }
  66. }
  67.  


« Última modificación: 24 Noviembre 2017, 02:15 am por solNegr0; » En línea



rubn0x52.com KNOWLEDGE  SHOULD BE FREE.
If you don't have time to read, you don't have the time (or the tools) to write, Simple as that. Stephen ki
Leyer


Desconectado Desconectado

Mensajes: 786


leyer@elhacker.net


Ver Perfil WWW
Re: code JRadioButton problema al seleccionar 2 JRadioButton
« Respuesta #1 en: 7 Enero 2012, 02:47 am »

tenias que agregarlos al ButtonGroup

Código
  1. grupo = new ButtonGroup();
  2. grupo.add(sumar);
  3. grupo.add(restar);
  4. add(sumar);
  5. add(restar);


En línea

rub'n


Desconectado Desconectado

Mensajes: 1.217


(e -> λ("live now")); tatuar -> λ("α");


Ver Perfil WWW
Re: code JRadioButton problema al seleccionar 2 JRadioButton
« Respuesta #2 en: 7 Enero 2012, 02:49 am »

gracias mi pana, todo calidad yoouu, y boorralo ejejje

saludos.  :)
En línea



rubn0x52.com KNOWLEDGE  SHOULD BE FREE.
If you don't have time to read, you don't have the time (or the tools) to write, Simple as that. Stephen ki
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problema con un code de Allegro « 1 2 »
Programación C/C++
vojok 10 6,094 Último mensaje 25 Julio 2010, 18:55 pm
por vojok
Cambiar Tamaño de Fuente JRadioButton...
Java
Leopola 6 4,819 Último mensaje 19 Febrero 2015, 19:50 pm
por Leopola
[SOURCE-CODE] Telerik Code Converter Client for Windows - by Elektro Studios « 1 2 »
.NET (C#, VB.NET, ASP)
Eleкtro 10 11,967 Último mensaje 12 Noviembre 2017, 13:04 pm
por Eleкtro
[SOURCE-CODE] Telerik Code Converter for Visual Studio - by Elektro Studios
.NET (C#, VB.NET, ASP)
Eleкtro 1 5,371 Último mensaje 12 Noviembre 2017, 13:05 pm
por Eleкtro
Java - Swing - JRadioButton « 1 2 »
Java
TickTack 16 4,843 Último mensaje 17 Noviembre 2018, 12:16 pm
por TickTack
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines