import java.awt.*;
import javax.swing.*;
import java.awt.event.*;public class JRadioButtonExample{
public static void main(String args[]){
RadioButtonFrame f=new RadioButtonFrame();
f.setSize(300,200);
f.show();
}
}class RadioButtonFrame extends JFrame{
private JLabel labPic=new JLabel();
private ActionListener listener=new RadioButtonListener();
private ButtonGroup group=new ButtonGroup();
private JPanel p=new JPanel();
RadioButtonFrame(){
p.setLayout(new GridLayout(4,0));
JRadioButton radMSSQL=new createRadioButton("MS SQL server");
JRadioButton radOracle=new createRadioButton("Oracle server");
JRadioButton radMysql=new createRadioButton("MySQL server");
radMSSQL.setSelected(true);
labPic.setText("当前使用的数据库为"+radMSSQL.getText());
p.add(labPic);
this.getContentPane().add(p,BorderLayout.WEST);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class JRadioButton createRadioButton(String text){
JRadioButton rb=new JRadioButton(text);
rb.addActionListener(listener);
group.add(rb);
p.add(rb);
return rb;
}
class RadioButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
labPic.setText("当前使用的数据库为"+
((JRadioButton)e.getSource()).getText());
}
}
}错误:
D:\Class\JRadioButtonExample.java:29: '{' expected
        class JRadioButton createRadioButton(String text){
                           ^
D:\Class\JRadioButtonExample.java:42: '}' expected
}
 ^
2 errorsProcess completed.我是个JAVA初学者,这个问题望高手解决.

解决方案 »

  1.   

    有很多编译错误,估计没用IDE吧!修改之后如下!
    记得给分啊!--------------------------------------------import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.ButtonGroup;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;public class JRadioButtonExample{
        public static void main(String args[]){
            RadioButtonFrame f=new RadioButtonFrame();
            f.setSize(300,200);
            f.show();   
        }   
    }class RadioButtonFrame extends JFrame{
        private JLabel labPic=new JLabel();
        private ActionListener listener=new RadioButtonListener();  
        private ButtonGroup group=new ButtonGroup();
        private JPanel p=new JPanel();
        RadioButtonFrame(){
            p.setLayout(new GridLayout(4,0));
            JRadioButton radMSSQL=createRadioButton("MS SQL server");
            JRadioButton radOracle=createRadioButton("Oracle server");
            JRadioButton radMysql=createRadioButton("MySQL server");
            radMSSQL.setSelected(true);
            labPic.setText("当前使用的数据库为"+radMSSQL.getText());
            p.add(labPic);
            this.getContentPane().add(p,BorderLayout.WEST);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        
        }   
        private JRadioButton createRadioButton(String text){
            JRadioButton rb=new JRadioButton(text);
            rb.addActionListener(listener);
            group.add(rb);
            p.add(rb);
            return rb;
        }
        class RadioButtonListener implements ActionListener{
            public void actionPerformed(ActionEvent e){
                labPic.setText("当前使用的数据库为" + ((JRadioButton)e.getSource()).getText());       
            }
        }
    }