如何限制选中的复选框? [英] How can I limit the check box selected?

查看:112
本文介绍了如何限制选中的复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们被告知要有10个复选框,并且只允许用户选中1-3个复选框.在用户单击表明他/她已完成要求的按钮之后,以及在计算机随机选择一个复选框之后.剩余的复选框将被视为优胜者.顺便说一下,这是一个游戏程序.
我正在使用Swing和AWT.

We were told to have 10 checkboxes and the user is only allowed to check 1-3 check boxes. After the user clicks a button indicating that he/she has completed the requirements and after the computer randomly selects a checkbox. The remaining checkbox wil be delared as a winner. This is a gaming program by the way.
I'm using Swing and AWT.

推荐答案

您可以通过禁用组件来限制复选框的选择或取消选择:

You can limit a checkbox being selectable or not by disabling the component:

JCheckBox checkBox = new JCheckBox("Try to click on me");
checkBox.setEnabled(false);

如果未启用(禁用)复选框,则用户无法选择它.

If a checkbox is not enabled (disabled), the user cannot select it.

这篇关于如何限制选中的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆