//radio buttons and check buttonsImportjava.awt.*;Importjavax.swing.*; Public classJiemian6extendsjframe{JPanel mb1,mb2,mb3; //Panel DefinitionJButton an1,an2;//button DefinitionJLabel bq1,bq2;//Label DefinitionJcheckbox Fxk1,fxk2,fxk3;//Multi-box definitionJradiobutton dx1,dx2;//radio button DefinitionButtongroup Dxz;//Put the radio button in a group, the default function is to choose only one, equivalent to the name of the HTML Public Static voidMain (string[] args) {//to run this class of construction methodsJiemian6 Jiemian =NewJiemian6 (); } PublicJiemian6 () {//Create a panelMB1 =NewJPanel (); MB2=NewJPanel (); MB3=NewJPanel (); //Create buttonBQ1 =NewJLabel ("Features:"); BQ2=NewJLabel ("Gender:"); An1=NewJButton ("register"); An2=NewJButton ("Cancel"); FXK1=NewJcheckbox ("Music"); FXK2=NewJcheckbox ("Sport"); FXK3=NewJcheckbox ("literary"); Dx1=NewJradiobutton ("Male"); DX2=NewJradiobutton ("female"); //Use grid layout This. setlayout (NewGridLayout (3,1)); //Add a group so that it can select only oneDXZ =NewButtongroup (); Dxz.add (DX1); Dxz.add (DX2); //Add a button to a panelMb1.add (BQ1); Mb1.add (FXK1); Mb1.add (FXK2); Mb1.add (FXK3); Mb2.add (BQ2); Mb2.add (DX1); Mb2.add (DX2); Mb3.add (AN1); Mb3.add (AN2); //Add a panel to the interface This. Add (MB1); This. Add (MB2); This. Add (MB3); //Set Window caption This. Settitle ("Layout Integrated Application"); //Set the width height of the window This. SetSize (300,150); //The Settings window appears for the location of the screen This. setlocation (100,100); //no pulling the big pull small This. setresizable (false); //releasing a resource after closing a window This. Setdefaultcloseoperation (Jframe.exit_on_close); //Output Window This. setvisible (true); } }
JAVA radio button, check button