This article describes the usage of swing radio box in Java. Share it for your reference. The details are as follows:
import java.awt.*;import javax.swing.*;import java.awt.event.*;public class test extends JAppletimizations ActionListener{ JTextField jtf; pub lic void init(){ Container contentPane = getContentPane(); contentPane.setLayout( new FlowLayout()); JRadioButton b1 = new JRadioButton("A"); b1.addActionListener(this); contentPane.add(b1); JRadioButton b2 = new JRadioButt on("B"); b2.addActionListener(this); contentPane .add(b2); JRadioButton b3 = new JRadioButton("C"); b3.addActionListener(this); contentPane.add(b3); ButtonGroup bg = new ButtonGroup(); bg.ad d(b1); bg.add( b2); bg.add(b3); jtf = new JTextField(15); contentPane.add(jtf); } public void actionPerformed(ActionEvent ae){ jtf.setText(ae.getActionComman d()); }}
I hope this article will be helpful to everyone's Java programming.