Java Code
/** Example showing multiple ButtonGroups of JRadioButtons
* @author : E.S.Boese
* @version: Fall 2008
*/
import javax.swing.*;
import java.awt.*;
public class JRadioMultiGroups extends JApplet
{
JRadioButton jb1, jb2, jb3, happy, mellow, sad;
ButtonGroup colors, mood;
Image img;
ImageIcon icon;
public void init( )
{
setLayout( new FlowLayout( ) );
jb1 = new JRadioButton( "red" );
jb2 = new JRadioButton( "blue" );
jb3 = new JRadioButton( "pink" );
happy = new JRadioButton( "Happy" );
mellow = new JRadioButton( "Mellow" );
sad = new JRadioButton( "Sad" );
addButtonIcons( jb1 ); addButtonIcons( jb2 );
addButtonIcons( jb3 ); addButtonIcons( happy );
addButtonIcons( mellow ); addButtonIcons( sad );
colors = new ButtonGroup( );
colors.add( jb1 ); colors.add( jb2 ); colors.add( jb3 );
mood = new ButtonGroup( );
mood.add( happy ); mood.add( mellow ); mood.add( sad );
add( jb1 ); add( jb2 ); add( jb3 );
add( happy ); add( mellow ); add( sad );
}
public void addButtonIcons( JRadioButton btn )
{
img = getImage( getCodeBase( ), "radioButtonRing.png");
icon = new ImageIcon( img );
btn.setIcon( icon );
img = getImage( getCodeBase( ), "radioButtonSelected.png" );
icon = new ImageIcon( img );
btn.setSelectedIcon( icon );
}
}
©2007-
by E.S.Boese. All Rights Reserved