Showing posts with label radio button. Show all posts
Showing posts with label radio button. Show all posts

Create radio button using JRadioButton

Source code below will show you, how to create a radio button in java with text HI using JRadioButton.

************************************************************************
COMPLETE SOURCE CODE FOR : CreateRadioButtonUsingJRadioButton.java
************************************************************************


import javax.swing.JRadioButton;
import javax.swing.JFrame;

public class CreateRadioButtonUsingJRadioButton
{
public static void main(String[]args)
{
//Create radio button with text HI
JRadioButton radioButton=new JRadioButton("HI");

//Create JFrame to place created JRadioButton
JFrame frame=new JFrame("Create radio button using JRadioButton");

//add created radio button into JFrame
frame.add(radioButton);

//set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//set JFrame size
frame.setSize(450,65);

//make your JFrame visible. So we can see it
frame.setVisible(true);
}
}


************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************

Create radio button in java

In java, you can create radio button using JRadioButton class.

Change java radio button text color

*********************************************************************
COMPLETE SOURCE CODE FOR : ChangeJavaRadioButtonTextColor.java
*********************************************************************


import javax.swing.JFrame;
import javax.swing.JRadioButton;

import java.awt.FlowLayout;
import java.awt.Color;

public class ChangeJavaRadioButtonTextColor
{
public static void main(String[]args)
{
JRadioButton a=new JRadioButton("I AM A RADIO BUTTON");
JFrame b=new JFrame("CHANGE RADIO BUTTON TEXT COLOR");
b.setLayout(new FlowLayout());

//METHOD setForeground will change radio button's text color
//You can see more color in Color class on Java API
a.setForeground(Color.GREEN);

b.add(a);

b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.setSize(400,400);
b.setVisible(true);
}
}


*********************************************************************
JUST COMPILE AND EXECUTE IT
*********************************************************************

RELAXING NATURE VIDEO