我用的是下拉框

import java.awt.event.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.*;
public class TestRadioButton extends JFrame implements ActionListener{
private JButton objT1;
private JLabel mobjlLabelTime;
private JTextField mobjS;
private JLabel objlabTemp;
private JComboBox mobjComboBox = null;
private String eL = ^[1-9]\\d*$;
public TestRadioButton() {
this.setResizable(false);
setSize(300,200);
mobjlLabelTime = new JLabel(输入值:);
mobjlLabelTime.setBounds(10, 45, 60, 30);
add(mobjlLabelTime);
mobjS = new JTextField(10);
mobjS.setBounds(60, 50, 50, 20);
add(mobjS);
String[] strBox = {平方, 阶乘};
mobjComboBox = new JComboBox(strBox);
mobjComboBox.setBounds(120, 50, 80, 20);
add(mobjComboBox);
objlabTemp = new JLabel(结果:);
objlabTemp.setBounds(10, 80, 300, 20);
add(objlabTemp);
objT1 = new JButton(计算);
objT1.setBounds(220, 40, 60, 30);
add(objT1);
objT1.addActionListener(this);
// 设置关闭程序
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args) {
TestRadioButton objPane = new TestRadioButton();
objPane.add(new JPanel());
objPane.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (objT1 == e.getSource()) {
String string= mobjComboBox.getSelectedItem().toString();
String strValue = mobjS.getText();
Pattern p = Pattern.compile(eL);
Matcher m = p.matcher(strValue);
boolean b = m.matches();
if (b) {
int ivalue = Integer.parseInt(strValue);
if (平方.equals(string)) {
string = 结果: + ivalue*ivalue;
} else {
int isum = 1;
for (int i = 2; i