RadioControl.java
资源名称:src.zip [点击查看]
上传用户:luxiaowei
上传日期:2022-06-06
资源大小:58k
文件大小:4k
源码类别:
J2ME
开发平台:
Java
- /*
- * RadioControl.java
- *
- * Created on April 23, 2010, 4:45 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
- package com.framework;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- /**
- *
- * @author Tejaswi
- */
- public class RadioControl extends UIControl{
- GTantra font;
- String text;
- private static final int PADDING = 3;
- TickerTextControl textControl;
- int radioCircleBorderColor;
- int radioFillColor;
- boolean isChecked = false;
- int radioWidth;
- RadioGroup parentGroup;
- Image radioButtonImg,radioButtonOnImg;
- /** Creates a new instance of RadioControl */
- public RadioControl(String text,GTantra font) {
- this.text = text;
- this.font = font;
- radioWidth = font.getFontHeight() - 4;
- textControl = new TickerTextControl(text,font);
- resize();
- }
- /** Creates a new instance of RadioControl */
- public RadioControl(String text,GTantra font , Image radioButtonImage,Image radioButtonOnImg) {
- this.text = text;
- this.font = font;
- this.radioButtonImg = radioButtonImage;
- this.radioButtonOnImg = radioButtonOnImg;
- radioWidth = this.radioButtonImg.getWidth();
- textControl = new TickerTextControl(text,font);
- setHeight(radioButtonImg.getHeight());
- resize();
- }
- public void showNotify() {
- super.showNotify();
- textControl.showNotify();
- textControl.setPoistion(radioWidth + PADDING , (getHeight() - textControl.getHeight()) >> 1);
- if(parentGroup != null)
- {
- parentGroup.showNotify();
- }
- }
- public void hideNotify() {
- super.hideNotify();
- textControl.hideNotify();
- }
- private void resize()
- {
- setWidth(textControl.getWidth() + PADDING + radioWidth);
- setHeight(Math.max(font.getFontHeight() + 2 ,getHeight()));
- }
- public void paint(Graphics g) {
- if(radioButtonImg == null)
- {
- g.setColor(radioCircleBorderColor);
- g.drawArc( 0 , (getHeight() - radioWidth) >> 1 , radioWidth,radioWidth, 0 , 360);
- if(isChecked)
- {
- g.setColor(radioFillColor);
- g.fillArc(3, ((getHeight() - radioWidth) >> 1) + 3 , radioWidth - 4 , radioWidth - 4 , 0 , 360);
- }
- }else{
- if(isChecked)
- {
- g.drawImage(radioButtonOnImg , 0, (getHeight() - radioButtonOnImg.getHeight()) >> 1 , 0);
- }else{
- g.drawImage(radioButtonImg , 0, (getHeight() - radioButtonImg.getHeight()) >> 1 , 0);
- }
- }
- textControl.paintUI(g);
- }
- public boolean isChecked()
- {
- return this.isChecked;
- }
- public void setChecked(boolean value)
- {
- this.isChecked = value;
- if(parentGroup != null)
- {
- parentGroup.selectionChanged(this);
- }
- }
- public boolean keyPressed(int keycode) {
- if(DisplayManager.getInst().getGameAction(keycode) == DisplayManager.FIRE && !isChecked)
- {
- if(parentGroup != null)
- {
- parentGroup.selectionChanged(this);
- }else{
- isChecked = true;
- }
- return true;
- }
- return false;
- }
- public void setRadioCircleBorderColor(int radioCircleBorderColor) {
- this.radioCircleBorderColor = radioCircleBorderColor;
- }
- public void setRadioFillColor(int radioFillColor) {
- this.radioFillColor = radioFillColor;
- }
- }