本文实例讲述了java之swing单选框用法。分享给大家供大家参考。具体如下:
import java.awt.*;import javax.swing.*;import java.awt.event.*;public class test extends JAppletimplements 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(15); contentPane.add(jtf); } public void actionPerformed(ActionEvent ae){ jtf.setText(ae.getActionCommand()); }}
希望本文所述对大家的java程序设计有所帮助。
新闻热点
疑难解答