2013-01-23 106 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(); 
    } 
};