GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Wednesday, December 22, 2010

Swing JRadioButton

To use this component, it's needed to use ButtonGroup:

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

public Main{

   public static void main(String[] args){

        JFrame frame = new JFrame("Radio Button");

        JRadioButton rbApel = new JRadioButton("Apel");
        JRadioButton rbNanas = new JRadioButton("Nanas");
        JRadioButton rbJambu = new JRadioButton("Jambu"):

        ButtonGroup group = new ButtonGroup();
        group.add(rbApel);
        group.add(rbNanas);
        group.add(rbJambu);

        frame.add(rbApel);
        frame.add(rbNanas);
        frame.add(rbJambu);

        frame.setSize(400, 300);
        frame.setLocation(200, 100);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
   }
}
Share/Bookmark

1 comment:

  1. I liked this article very much. The content is very good. Keep posting.
    Visit us: Java Training
    Visit us: Java Course

    ReplyDelete