1 /* 2 * File: CheckboxGroupDemo.java 3 * 4 * Create some radio buttons 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.awt.Color; 11 import java.awt.Checkbox; 12 import java.awt.CheckboxGroup; 13 import java.awt.Panel; 14 15 public class CheckboxGroupDemo extends java.applet.Applet { 16 17 private int n = 6; // number of radio buttons 18 private Checkbox[] radioButton = new Checkbox[n]; 19 private CheckboxGroup radioButtons = new CheckboxGroup(); 20 21 public void init() { 22 setBackground( Color.white ); 23 Color lightBlue = new Color( 0xB0, 0xE0, 0xE6 ); 24 Color navyBlue = new Color( 0x19, 0x19, 0x70 ); 25 26 String[] colorLabel = new String[n]; 27 colorLabel[0] = "Red"; colorLabel[1] = "Blue"; 28 colorLabel[2] = "Yellow"; colorLabel[3] = "Green"; 29 colorLabel[4] = "Orange"; colorLabel[5] = "Purple"; 30 31 // Instantiate radio buttons and add them to a panel: 32 Panel radioButtonPanel = new Panel(); 33 radioButtonPanel.setBackground( lightBlue ); 34 for ( int i = 0; i < n; i++ ) { 35 radioButton[i] = new Checkbox( colorLabel[i], radioButtons, false ); 36 radioButton[i].setForeground( navyBlue ); 37 radioButton[i].setBackground( lightBlue ); 38 radioButtonPanel.add( radioButton[i] ); 39 } 40 radioButtons.setSelectedCheckbox( radioButton[0] ); 41 42 add( radioButtonPanel ); 43 } 44 45 }