Java Code




/** Example showing use of JRadioButton
  * @author : E.S.Boese (c) Fall 2005
  */
import javax.swing.*;
import java.awt.*;
public class JRadioButtonMethods extends JApplet
{
   JRadioButton jb1, jb2, jb3;
   ButtonGroup group;

   public void init( )
   {
		setLayout( new FlowLayout( )   );
		setupRadioButtons( );	// calls the method listed below

		group.add( jb1 );
		group.add( jb2 );
		group.add( jb3 );

		add( jb1 );
		add( jb2 );
		add( jb3 );
   }
   public void setupRadioButtons( )
   {
		jb1 = new JRadioButton( "red" );
		jb2 = new JRadioButton( "blue" );
		jb3 = new JRadioButton( "pink" );
		group = new ButtonGroup( );
   }
}

Back to Code Examples
©2006- by E.S.Boese. All Rights Reserved