
write a program to create an applet button which has a list of radio buttons with titles of various colours.set the background colour of the applet to the selected colour

Here is an applet example which has a list of radio buttons with titles of various colors and a button. The given code sets the background color of applet according to the radio button selected by the user.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class GetSelectedRadioButton extends Applet implements ItemListener,ActionListener{
CheckboxGroup gp = null;
public void init(){
gp = new CheckboxGroup();
Checkbox c1 = new Checkbox("RED", gp, true);
Checkbox c2 = new Checkbox("GREEN", gp, false);
Checkbox c3 = new Checkbox("BLUE", gp, false);
Button b=new Button("OK");
add(c1);
add(c2);
add(c3);
add(b);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
b.addActionListener(this);
}
public void itemStateChanged(ItemEvent ie) {
repaint();
}
public void actionPerformed(ActionEvent e){
Checkbox chk = gp.getSelectedCheckbox();
if(chk.getLabel().equals("RED")){
setBackground(Color.RED);
}
if(chk.getLabel().equals("GREEN")){
setBackground(Color.GREEN);
}
if(chk.getLabel().equals("BLUE")){
setBackground(Color.BLUE);
}
}
}
Now to call the above applet, you need to create an html code. Here it is:
<HTML> <BODY> <APPLET CODE ="GetSelectedRadioButton.class" WIDTH="800" HEIGHT="500"></APPLET> </BODY> </HTML>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.