Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


aman sagar
radio buttons
1 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners


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


Advertisement
View Answers

August 22, 2012 at 2:58 PM


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>


Related Tutorials/Questions & Answers:
radio buttons
radio buttons  write a program to create an applet button which has a list of radio buttons with titles of various colours.set the background colour... has a list of radio buttons with titles of various colors and a button
Radio Buttons - Java Beginners
Radio Buttons  Hello Sir, How to create the code for the password... the radion buttons in display the same page in jsp.I need only how to make the question and answer page using the radio buttons.please help me to solve
Advertisements
Radio Buttons in Jsp - JSP-Servlet
Radio Buttons in Jsp  Hi, i have a page in which there are lot of radio buttons [IMG]http://i38.tinypic.com/jzi6vc.jpg[/IMG] see the above picture..." depending on the value in the String radio button has to be checked. How to do
Radio Buttons in DB Very Urgent - JSP-Servlet
Radio Buttons in DB Very Urgent  Respected Sir/Madam, I am... in the database.Here I need Radio Buttons added dynamically for each Row. When I click the corresponding Radio Button and Submit,The Emp ID and Emp Name must
Tab sequence problem with Radio buttons - JSP-Servlet
Tab sequence problem with Radio buttons  Hi, I have membership type in application as 1 year(radio button) 2 year(radio button) 4 year(radio button) courier delivery courier(radio button) currently tab sequence going
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem. i have a system to input data from a jform to a mysql database. i have made all of it except the gender radiobuttons. how do i do this? i need when register
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem. i have a system to input data from a jform to a mysql database. i have made all of it except the gender radiobuttons. how do i do this? i need when register
WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS - Struts
for check boxes and radio buttons and for submit buttons. i have a jsp page which contains check boxes,radio buttons.and when i click submit button the related...WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS 
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, i am getting error in my code of feedback form. once i finished selecting all the radio buttons and when i click on delete button. it points to the answer.jsp. answer.jsp
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, my problem... of radio buttons. the feedback.jsp should look like same as follows: Please... as per his choice. when user completes all the selection of radio buttons and he
Display Label and radio buttons runtime with respect to DB values
Display Label and radio buttons runtime with respect to DB values  Requirement: I am getting alertCondition,Y,W values from DB the the cooresponding fields like the following: JLbel- alertCondition-"alert1","Alert2" JradioButton
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has the option field as options. but it is option in the table,so i changed
Radio buttons in html
Radio buttons in html Here is an example of radio button in html.In this example we have display two radio button Male and Female. The user select only one.... Example radioButton.html <html> <head><title>Radio button
Radio Buttons in HTML
Radio Buttons in HTML     ... The Tutorial illustrates an example from Radio Buttons in HTML.In this Tutorial, the code explain to create a Radio Buttons. The code enables a user to select one
Buttons
Buttons  I have created a web page with radio button group with two radio buttons for accepting the home appliances categories,Kitchen appliances... radio button is selected.Which event listener do I need to implement for this task
Create Radio Buttons in SWT
Create Radio Buttons in SWT       This section illustrates you how to create radio button. In SWT, the style RADIO defined in the Button class allows to create radio button. We
need help for writting code in struts action class for check boxes and radio buttons - Struts
people.iwould like to write code in struts action class for check boxes and radio buttons and for submit buttons. i have a jsp page which contains check boxes,radio...need help for writting code in struts action class for check boxes and radio
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL
how to access radio buttons selected in a servlet??...iam unable to retrieve...; <p>4.what is currency of USA?</p> <input type="radio...; <input type="radio" name="d" onclick="getAnswer('b')" value="b "/>pound
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL
how to access radio buttons selected in a servlet??...iam unable to retrieve...; <p>4.what is currency of USA?</p> <input type="radio...; <input type="radio" name="d" onclick="getAnswer('b')" value="b "/>pound
Dojo Radio Button
; In this section, you will learn how to create radio buttons in dojo...(dijit.form.CheckBox) for RadioButtons to work. [Radio buttons are used when there is a list....] Radio Buttons are the same as html but dojo provides more controls and styling
Selecting a Radio Button component in Java
shows five radio buttons with labeled by "First", "Second"...-different radio buttons. Following are the screen shots for the result... Selecting a Radio Button component in Java   
radio nuttpn
radio nuttpn  i have created a html page containing 20 multiple choice questions when i clicl the options which are radio buttons. I have tp retroebe it in a jsp pahe ansabe it in mysql database...further i have to match
radio button
radio button  On selecting a radio button, it should open a aspx page
Struts 2 Radio Button
Struts 2 Radio Button  I have a search functionlaity where i have two radio buttons and I am using Struts2 tag.I want first rado button to be selected by default.But when i select the second radio button and hit on search
add Buttons in JavaScript
add Buttons in JavaScript  How to add Buttons in JavaScript
Radio button in JSP - JSP-Servlet
Radio button in JSP  Hi! In my page I have two radio buttons. If i select first radio button. one text field has to be displayed.... If i select second radio button. text field has to be disappeared. pls.... help me.. 
dependent radio button
dependent radio button  Hi. I have 4 radio buttons say all,chocolate,cookie,icecream. If I select all the other 3 should not able to be selected... of the Radio Button is to select only one option at a time. So you don't need
uinavigationcontroller add multiple buttons
uinavigationcontroller add multiple buttons  How to add multiple buttons to the UINavigationController
HTML custom buttons
HTML custom buttons  How can I make a form with custom buttons
Advertisements
 

 

 

DMCA.com