The example in this article describes the use of the Swing radio box in Java. Share to everyone for your reference. Specifically as follows:
Import java.awt.*;
Import javax.swing.*;
Import java.awt.event.*;
public class Test extends JApplet
implements actionlistener{
JTextField JTF;
public void init () {
Container ContentPane = Getcontentpane ();
Contentpane.setlayout (New FlowLayout ());
Jradiobutton B1 = new Jradiobutton ("A");
B1.addactionlistener (this);
Contentpane.add (B1);
Jradiobutton b2 = new Jradiobutton ("B");
B2.addactionlistener (this);
Contentpane.add (B2);
Jradiobutton B3 = new Jradiobutton ("C");
B3.addactionlistener (this);
Contentpane.add (b3);
Buttongroup bg = new Buttongroup ();
Bg.add (B1);
Bg.add (B2);
Bg.add (b3);
JTF = new JTextField ();
Contentpane.add (JTF);
}
public void actionperformed (ActionEvent ae) {
jtf.settext (Ae.getactioncommand ());
}
I hope this article will help you with your Java programming.