就是点击JRadioButton时,显示另外的一个页面~~~~~~~~我该怎么做??JRadioButton jRadioButton1 = new JRadioButton("网口");
JRadioButton jRadioButton2 = new JRadioButton("COM/USB");
JRadioButton jRadioButton3 = new JRadioButton("ActiveX控件");
JRadioButton jRadioButton4 = new JRadioButton("其它");
JRadioButton jRadioButton2 = new JRadioButton("COM/USB");
JRadioButton jRadioButton3 = new JRadioButton("ActiveX控件");
JRadioButton jRadioButton4 = new JRadioButton("其它");
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
public class JRadioButtonDemo extends JFrame implements ActionListener{
JRadioButton jRadioButton1 = new JRadioButton("网口");
JRadioButton jRadioButton2 = new JRadioButton("COM/USB");
JRadioButton jRadioButton3 = new JRadioButton("ActiveX控件");
JRadioButton jRadioButton4 = new JRadioButton("其它");
ButtonGroup bg=new ButtonGroup();
public JRadioButtonDemo(){
bg.add(jRadioButton1);
bg.add(jRadioButton2);
bg.add(jRadioButton3);
bg.add(jRadioButton4);
jRadioButton1.addActionListener(this);
jRadioButton2.addActionListener(this);
jRadioButton3.addActionListener(this);
jRadioButton4.addActionListener(this);
Container c=this.getContentPane();
c.setLayout(new FlowLayout());
c.add(jRadioButton1);
c.add(jRadioButton2);
c.add(jRadioButton3);
c.add(jRadioButton4);
this.setSize(200,200);
this.setVisible(true);
}
public static void main(String[] args){
new JRadioButtonDemo();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jRadioButton1){
JFrame f1=new JFrame();
f1.setSize(100,100);
f1.setVisible(true);
}
else if(e.getSource()==jRadioButton2){
JFrame f2=new JFrame();
f2.setSize(100,100);
f2.setVisible(true);
}
else if(e.getSource()==jRadioButton3){
JFrame f3=new JFrame();
f3.setSize(100,100);
f3.setVisible(true);
}
else if(e.getSource()==jRadioButton4){
JFrame f4=new JFrame();
f4.setSize(100,100);
f4.setVisible(true);
}
}
}
再添加监听器上去,点哪个JRadioButton就执行哪个getPanel()方法
这是我的思路希望对你有帮助