Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

how get radiobutton index in textfield

Hi master
Sir this is my class i am using the radio button and textfield
===============
public class radio extends javax.swing.JApplet {
public void init() {
initComponents();
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
buttonGroup1.add(jRadioButton3);
}
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton3 = new javax.swing.JRadioButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();

getContentPane().setLayout(null);

jRadioButton1.setText("jRadioButton1");
getContentPane().add(jRadioButton1);
jRadioButton1.setBounds(140, 30, 104, 24);

jRadioButton2.setText("jRadioButton2");
getContentPane().add(jRadioButton2);
jRadioButton2.setBounds(150, 60, 104, 24);

jRadioButton3.setText("jRadioButton3");
getContentPane().add(jRadioButton3);
jRadioButton3.setBounds(170, 90, 104, 24);

jTextField1.setText("jTextField1");
getContentPane().add(jTextField1);
jTextField1.setBounds(100, 180, 150, 20);

jTextField2.setText("jTextField2");
getContentPane().add(jTextField2);
jTextField2.setBounds(100, 140, 140, 30);

}
// Variables declaration - do not modify
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration

}

=======================================================================
Sir my need is when user select any one radio button then
radioButton index move replace in textfield1 and radioButton title move in textfield2
because i save the radiobutton index in database
and when form start then which button true that value received 1 form database

please give me idea how I control my program

thank

aamir
[2225 byte] By [mfa] at [2007-11-11 10:10:46]
# 1 Re: how get radiobutton index in textfield
I would really like to help you, but I fail to decode what your problem is. Please rephrase your question. Apart from that I cannot see any need for a database to resolve any problem whatsoever in the setup you have presented here.

As for the radiobutton "index"; If you implement an Actionlistener in your applet you can always check which button is clicked by this approach:

public void actionPerformed(ActionEvent e) {
if (e.getSource()==jRadioButton1) {
// blabla
} else if (e.getSource()==jRadioButton2) {
// blabla
} else if (etc. etc.)..
}
sjalle at 2007-11-11 22:31:53 >