domingo, 17 de febrero de 2013

JRadioButton Programador Java Interfaz Gráfico GUI AWT Swing 1 Swing 2

Programador Java Interfaz Gráfico GUI AWT Swing 1 Swing 2
JRadioButton Java Interfaz Gráfico GUI AWT Swing 1 Swing 2
JradioButton

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


public class jradiobutton extends Frame {

  private JLabel jLabel1 = new JLabel();
  private JPanel jPanel1 = new JPanel(null, true);
    private JRadioButton jRadioButton1 = new JRadioButton();
    private JRadioButton jRadioButton2 = new JRadioButton();
    private JRadioButton jRadioButton3 = new JRadioButton();
  private JLabel jLabel2 = new JLabel();
  private JButton jButton1 = new JButton();
    private ImageIcon jButton1Icon = new ImageIcon("../../gra.png");


  public jradiobutton(String title) {

    super(title);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent evt) { dispose(); }
    });
    int frameWidth = 326;
    int frameHeight = 329;
    setSize(frameWidth, frameHeight);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    setResizable(false);
    Panel cp = new Panel(null);
    add(cp);

  
    cp.setBackground(new Color(0x39C64F));
    jLabel1.setBounds(24, 0, 232, 65);
    jLabel1.setText("JRadioButton");
    jLabel1.setFont(new Font("3D", Font.BOLD, 36));
    jLabel1.setForeground(Color.CYAN);
    cp.add(jLabel1);
    jPanel1.setBounds(24, 64, 233, 137);
    jPanel1.setOpaque(false);
    jPanel1.setBorder(BorderFactory.createEtchedBorder(0, Color.BLACK, Color.BLACK));
    jPanel1.setToolTipText("");
    cp.add(jPanel1);
    jRadioButton1.setBounds(32, 16, 105, 25);
    jRadioButton1.setText("Rojo");
    jRadioButton1.setOpaque(false);
    jPanel1.add(jRadioButton1);
    jRadioButton2.setBounds(32, 56, 97, 25);
    jRadioButton2.setText("Amarillo");
    jRadioButton2.setOpaque(false);
    jPanel1.add(jRadioButton2);
    jRadioButton3.setBounds(32, 88, 129, 33);
    jRadioButton3.setText("Verde");
    jRadioButton3.setOpaque(false);
    jPanel1.add(jRadioButton3);
    jLabel2.setBounds(24, 208, 187, 33);
    jLabel2.setText("Color Seleccionado:");
    cp.add(jLabel2);
    jButton1.setBounds(88, 256, 113, 41);
    jButton1.setText("Aceptar");
    jButton1.setMargin(new Insets(2, 2, 2, 2));
    jButton1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jButton1_ActionPerformed(evt);
      }
    });
    jButton1.setIcon(jButton1Icon);
    cp.add(jButton1);

  
    setVisible(true);
  }

  public void jButton1_ActionPerformed(ActionEvent evt) {
    String mensaje="Color Seleccionado: ";
  
    if (jRadioButton1.isSelected()) {
      mensaje=mensaje+"Rojo";
    } else if (jRadioButton2.isSelected()) {
      mensaje=mensaje+"Amarillo";
    } else if (jRadioButton3.isSelected()) {
      mensaje=mensaje+"Verde";
    }
  
    jLabel2.setText(mensaje);
  
  
  }
  
  public static void main(String[] args) {
    new jradiobutton("jradiobutton");
  }

}

No hay comentarios:

Publicar un comentario