RadioGroup.java
资源名称:src.zip [点击查看]
上传用户:luxiaowei
上传日期:2022-06-06
资源大小:58k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- /*
- * RadioGroup.java
- *
- * Created on April 23, 2010, 5:35 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
- package com.framework;
- import java.util.Vector;
- /**
- *
- * @author Tejaswi
- */
- public class RadioGroup {
- Vector vector = new Vector();
- /** Creates a new instance of RadioGroup */
- public RadioGroup() {
- }
- public void addRadioControl(RadioControl control)
- {
- vector.addElement(control);
- control.parentGroup = this;
- }
- protected void showNotify()
- {
- int selIndex = getSelectedIndex();
- if(vector.size() > 0 && selIndex == -1)
- {
- ((RadioControl)vector.elementAt(0)).isChecked = true;
- }
- }
- protected void selectionChanged(RadioControl control)
- {
- int selIndex = getSelectedIndex();
- int compIndex = getIndex(control);
- if(compIndex != selIndex)
- {
- for(int i = 0 ; i < vector.size() ; i ++)
- {
- RadioControl radioControl = (RadioControl)vector.elementAt(i);
- if(i == compIndex)
- {
- radioControl.isChecked = true;
- }else{
- radioControl.isChecked = false;
- }
- }
- }
- }
- public int getIndex(RadioControl control)
- {
- for(int i = 0 ; i < vector.size() ; i ++)
- {
- RadioControl radioControl = (RadioControl)vector.elementAt(i);
- if(radioControl.equals(control))
- {
- return i;
- }
- }
- return -1;
- }
- public int getSelectedIndex()
- {
- for(int i = 0 ; i < vector.size() ; i ++)
- {
- RadioControl radioControl = (RadioControl)vector.elementAt(i);
- if(radioControl.isChecked())
- {
- return i;
- }
- }
- return -1;
- }
- }