Frame with radio button

import javax.swing.*;
public class FrameDemo8 extends JFrame 
{
	public FrameDemo8()
	{
		super("techmyguru.com");
		setSize(500,600);
	 getContentPane().add(new RadioButtonDemo());
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
	}
	public static void main(String[] args) 
	{
	new FrameDemo8();
	}
}

Download

RadioButtonDemo.java

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

public class RadioButtonDemo extends JPanel {
	static String birdString = "Bird";
	static String catString = "Cat";
	static String dogString = "Dog";
	static String rabbitString = "Rabbit";
	static String pigString = "Pig";
	JLabel picture;

	public RadioButtonDemo() {
		super();
		// Create the radio buttons.
		JRadioButton birdButton = new JRadioButton(birdString);
		birdButton.setMnemonic(KeyEvent.VK_B);
		birdButton.setActionCommand(birdString);
		birdButton.setSelected(true);

		JRadioButton catButton = new JRadioButton(catString);
		catButton.setMnemonic(KeyEvent.VK_C);
		catButton.setActionCommand(catString);

		JRadioButton dogButton = new JRadioButton(dogString);
		dogButton.setMnemonic(KeyEvent.VK_D);
		dogButton.setActionCommand(dogString);

		JRadioButton rabbitButton = new JRadioButton(rabbitString);
		rabbitButton.setMnemonic(KeyEvent.VK_R);
		rabbitButton.setActionCommand(rabbitString);

		JRadioButton pigButton = new JRadioButton(pigString);
		pigButton.setMnemonic(KeyEvent.VK_P);
		pigButton.setActionCommand(pigString);

		// Group the radio buttons.
		ButtonGroup group = new ButtonGroup();
		group.add(birdButton);
		group.add(catButton);
		group.add(dogButton);
		group.add(rabbitButton);
		group.add(pigButton);
		// Set up the picture label.
		picture = new JLabel(createImageIcon("images/" + birdString + ".gif"));
		add(birdButton);
		add(catButton);
		add(dogButton);
		add(rabbitButton);
		add(pigButton);
		add(picture);
	}

	protected static ImageIcon createImageIcon(String path) {
		java.net.URL imgURL = RadioButtonDemo.class.getResource(path);
		if (imgURL != null) {
			return new ImageIcon(imgURL);
		} else {
			System.err.println("Couldn't find file: " + path);
			return null;
		}
	}

}

Download

Frame in Swing

Simple Frame
Frame with Panel
Frame Menu Event ans Color Chooser
Frame with Panel and Button
TextField and TextArea
Combobox in Frame
Change Icon of Frame
Scrollbar in Frame
Scrollbar in Frame
Add picture in Frame
Label in Frame
Toggle Buttons in frame
Radio Buttons in Frame


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code