2013-01-23 51 views
-1

我有2个单选按钮,'是'和'不'。 点击是按钮后,我需要在同一帧下面的3个级别。单选按钮点击动作挥杆

1你的名字是什么? ---------

2您的年龄? ---------

3性别? --------

类似地,点击没有按钮后,这些级别将不会显示在框架中。

请帮我解决这个问题。

我试图像点击单选按钮,它会显示在JOptionPane中的消息通过showMessageDialog.but未能解决这一

+0

你的问题是?你有什么尝试? – lbalazscs

+0

我们会尽力帮助您,但您应该先尝试。 – Amarnath

回答

2

你需要做的,就是添加额外的组件,如果您想以显示YES JRadioButton的选择,并将它们全部放在JPanel上。

现在上的YES JRadioButton选择,只需到JPanel, that is holding both the JRadioButton and this newly created JPanel添加此JPanel,并调用frame.pack(),如图下面的例子。

private ActionListener radioActions = new ActionListener() { 
    @Override 
    public void actionPerformed(ActionEvent e) { 
     if (e.getSource() == yesRButton) 
     { 
      if (!selectionPanel.isShowing()) 
       contentPane.add(selectionPanel); 
     } 
     else if (e.getSource() == noRButton) 
     { 
      if (selectionPanel.isShowing()) 
       contentPane.remove(selectionPanel); 
     } 
     frame.pack(); 
    } 
};