Write a snippet of Java code not an entire program to create

Write a snippet of Java code (not an entire program) to create three radio buttons that are used to select ice cream flavors: Chocolate, Strawberry, and Vanilla. Chocolate should be the default selected flavor.

Solution

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;


class Rb extends JFrame {
Rb (){
JRadioButton Chocolate = new JRadioButton(\"Chocolate\");
JRadioButton Strawberry = new JRadioButton(\"Strawberry\");
JRadioButton Vanilla = new JRadioButton(\"Vanilla\");
ButtonGroup bG = new ButtonGroup();
bG.add(Chocolate);
bG.add(Strawberry);
bG.add(Vanilla);
this.setSize(100,300);
this.setLayout( new FlowLayout());
this.add(Chocolate);
this.add(Strawberry);
this.add(Vanilla);
Chocolate.setSelected(true);
this.setVisible(true);
}
public static void main(String args[]){
Rb flavour = new Rb();
}
}

 Write a snippet of Java code (not an entire program) to create three radio buttons that are used to select ice cream flavors: Chocolate, Strawberry, and Vanill

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site