是否选择了活动选项卡式收音机?

发布于 2025-01-13 16:00:18 字数 1641 浏览 1 评论 0原文

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TabbedPaneExample {
JFrame f;
TabbedPaneExample(){
f=new JFrame();

    JButton check = new JButton("Check state of RadioButton");
    check.setBounds(50,280,200,60);
    //selected tabbed radio button is selected ?

    JPanel p1=new JPanel();
    JPanel p2=new JPanel();
    JPanel p3=new JPanel();
    JRadioButton rb1 = new JRadioButton("Radio");
    JRadioButton rb2= new JRadioButton("Radio");
    JRadioButton rb3 = new JRadioButton("Radio");
    rb1.setBounds(150,170,80,100);
    rb2.setBounds(150,170,80,100);
    rb3.setBounds(150,170,80,100);
    p1.add(rb1);
    p2.add(rb2);
    p3.add(rb3);
    JTabbedPane tp=new JTabbedPane();
    tp.setBounds(50,50,200,200);
    tp.add("main",p1);
    tp.add("visit",p2);
    tp.add("help",p3);

    check.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            
            // Q: is the radio button of the selected tab is checked
            // what is the logic i can put here to get result
            // show result into JOptionPane
        }
    });


    f.add(tp);
    f.add(check);
    f.setSize(400,400);
    f.setLayout(null);
    f.setVisible(true);
}
public static void main(String[] args) {
    new TabbedPaneExample();

}}

问:显示活动选项卡的单选按钮状态(选中或未选中):

https://i.sstatic.net/0pjIM.jpg

我有三个选项卡,这些选项卡有单选按钮,我想获取状态(选择或相对于任何活动选项卡的单选按钮!

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TabbedPaneExample {
JFrame f;
TabbedPaneExample(){
f=new JFrame();

    JButton check = new JButton("Check state of RadioButton");
    check.setBounds(50,280,200,60);
    //selected tabbed radio button is selected ?

    JPanel p1=new JPanel();
    JPanel p2=new JPanel();
    JPanel p3=new JPanel();
    JRadioButton rb1 = new JRadioButton("Radio");
    JRadioButton rb2= new JRadioButton("Radio");
    JRadioButton rb3 = new JRadioButton("Radio");
    rb1.setBounds(150,170,80,100);
    rb2.setBounds(150,170,80,100);
    rb3.setBounds(150,170,80,100);
    p1.add(rb1);
    p2.add(rb2);
    p3.add(rb3);
    JTabbedPane tp=new JTabbedPane();
    tp.setBounds(50,50,200,200);
    tp.add("main",p1);
    tp.add("visit",p2);
    tp.add("help",p3);

    check.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            
            // Q: is the radio button of the selected tab is checked
            // what is the logic i can put here to get result
            // show result into JOptionPane
        }
    });


    f.add(tp);
    f.add(check);
    f.setSize(400,400);
    f.setLayout(null);
    f.setVisible(true);
}
public static void main(String[] args) {
    new TabbedPaneExample();

}}

Q: show radio button state(selected or unselected) of the active tab:

https://i.sstatic.net/0pjIM.jpg

I have three tab and these tab have the radio button, I want to get state(selected or unselected) of the radio button with respect to any active tab!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文