Sunday, 14 October 2012

Java JRadioButton Demo program

// JAVA Program  for demonstration of JRadioButton

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/*
<applet code="JRadioButtonDemo" width=500 height=50>
</applet>
*/

public class JRadioButtonDemo extends JApplet
implements ActionListener {
JTextField jtf;

public void init(){

// Get content pane
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());

// ADD radio buttons to content pane
JRadioButton b1 = new JRadioButton("B.Sc");
b1.addActionListener(this);
contentPane.add(b1);

JRadioButton b2 = new JRadioButton("M.Sc");
b2.addActionListener(this);
contentPane.add(b2);

JRadioButton b3 = new JRadioButton("B.Tech");
b3.addActionListener(this);
contentPane.add(b3);

JRadioButton b4 = new JRadioButton("M.Tech");
b4.addActionListener(this);
contentPane.add(b4);

JRadioButton b5 = new JRadioButton("M.C.A");
b5.addActionListener(this);
contentPane.add(b5);

// Define a button group
ButtonGroup bg = new ButtonGroup();
bg.add(b1);
bg.add(b2);
bg.add(b3);
bg.add(b4);
bg.add(b5);

// Add text field to the content pane
jtf = new JTextField(15);
contentPane.add(jtf);
}
public void actionPerformed(ActionEvent ae){
jtf.setText(ae.getActionCommand());
}
}



Post a Comment