验证 jframe 组合框以便不接受默认值
Validating jframe combo box so that the default is not accepted
我正在尝试确保这些组合框没有默认值。
这是我目前用来验证它的代码
public boolean checked() {
/*this code loops through all comboboxes, checks they are not default
* and adds 1 to i. if i is 6, by the end of then it means that none
* are default and true is returned
*/
int i = 0;
if(!drop1.equals("Year")){
i++;
}
if (!drop2.equals("Month")) {
i++;
}
if (!drop3.equals("Day")) {
i++;
}
if (!drop4.equals("Year Group")) {
i++;
}
if (!drop5.equals("Year")) {
i++;
}
if (!drop6.equals("Year")) {
i++;
}
if (i == 6) {
return true;
} else {
return false;
}
}
dropX 是单独的投递箱
在查看了 jcombobox 的 class 方法之后,我想到了这个:
public boolean checked(){
/*this code loops through all comboboxes, checks they are not default
* and adds 1 to i. if i is 6, by the end of then it means that none
* are default and true is returned
*/
int i = 0;
if(drop1.getSelectedIndex() != 0){
i++;
}
if(drop2.getSelectedIndex() != 0){
i++;
}
if(drop3.getSelectedIndex() != 0){
i++;
}
if(drop4.getSelectedIndex() != 0){
i++;
}
if(drop5.getSelectedIndex() != 0){
i++;
}
if(drop6.getSelectedIndex() != 0){
i++;
}
if(i == 6){
return true;
}else{
return false;
}
}
getSelectedIndex() 确定组合框的状态。如果组合框是默认的(值 0),那么我永远不会达到 6。
我正在尝试确保这些组合框没有默认值。
这是我目前用来验证它的代码
public boolean checked() {
/*this code loops through all comboboxes, checks they are not default
* and adds 1 to i. if i is 6, by the end of then it means that none
* are default and true is returned
*/
int i = 0;
if(!drop1.equals("Year")){
i++;
}
if (!drop2.equals("Month")) {
i++;
}
if (!drop3.equals("Day")) {
i++;
}
if (!drop4.equals("Year Group")) {
i++;
}
if (!drop5.equals("Year")) {
i++;
}
if (!drop6.equals("Year")) {
i++;
}
if (i == 6) {
return true;
} else {
return false;
}
}
dropX 是单独的投递箱
在查看了 jcombobox 的 class 方法之后,我想到了这个:
public boolean checked(){
/*this code loops through all comboboxes, checks they are not default
* and adds 1 to i. if i is 6, by the end of then it means that none
* are default and true is returned
*/
int i = 0;
if(drop1.getSelectedIndex() != 0){
i++;
}
if(drop2.getSelectedIndex() != 0){
i++;
}
if(drop3.getSelectedIndex() != 0){
i++;
}
if(drop4.getSelectedIndex() != 0){
i++;
}
if(drop5.getSelectedIndex() != 0){
i++;
}
if(drop6.getSelectedIndex() != 0){
i++;
}
if(i == 6){
return true;
}else{
return false;
}
}
getSelectedIndex() 确定组合框的状态。如果组合框是默认的(值 0),那么我永远不会达到 6。