[英]How can I enable/activate a radio button after a button is clicked?
在Java中使用jFrame,我有一組單選按鈕,但是我希望一旦選擇了某個按鈕,就可以激活這些單選按鈕。 最簡單的方法是什么? 謝謝
ActionListener
添加到按鈕。 actionPerformed()
以啟用單選按鈕。 這是Oracle教程 。
這是TutorialsPoint教程 。
這是禁用單選按鈕的小示例。
JButton button = new JButton("Click");
JRadioButton one= new JRadioButton("one");
JRadioButton two= new JRadioButton("two");
JRadioButton three = new JRadioButton("three");
one.setEnabled(false);
two.setEnabled(false);
three.setEnabled(false);
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(one);
group.add(two);
group.add(three);
//Add action listener to button
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// enable radion buttons.
one.setEnabled(true);
two.setEnabled(true);
three.setEnabled(true);
}
});
這是一個演示想法,這件事是如何工作的。 這只是一個基本的演示。 生成的按鈕和單選按鈕。 當單擊按鈕時,您可以啟用它們。
01.生成按鈕和三個用於jframe的單選按鈕。
02.生成按鈕組並添加這些單選按鈕。
03.在按鈕動作偵聽器中添加“ 啟用單選按鈕 ”代碼。
該鏈接將對您確實有幫助。 好好看一下。
你管鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.