Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

JRadioButton

The JButton class which extends AbstractButton class that is used to create a button. JButton supports ActionEvent, that means when a button is clicked, an ActionEvent is generated.

Basically radio button is a group of related button from which one can be selected only. JRadioButton class is used to create a radio button in Frames. JRadioButton having following constructor,
JRadioButton(String s)

JRadioButton Example

importjava.awt.event.*;
importjava.awt.*;
public class JRadioButtonDemo extends JFrame
{
	publicJRadioButtonDemo() 
	{
		JRadioButtonjcb = new JRadioButton("A");	//creating JRadioButton.  
		add(jcb);					//adding JRadioButton to frame. 
		jcb = new JRadioButton("B");			//creating JRadioButton. 
		add(jcb);					//adding JRadioButton to frame. 
		jcb = new JRadioButton("C");			//creating JRadioButton.  
		add(jcb);					//adding JRadioButton to frame. 
		jcb = new JRadioButton("none");
		add(jcb);
		setLayout(new FlowLayout());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(300, 300);
		setVisible(true);
	}
	public static void main(String[] args)
	{
		newJRadioButtonDemo();
	}
}
Output:

pic


About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext