ImageControl.java
资源名称:src.zip [点击查看]
上传用户:luxiaowei
上传日期:2022-06-06
资源大小:58k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.framework;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- /**
- *
- * @author swaroop_kumar
- */
- public class ImageControl extends UIControl implements TimerInterface{
- Image image;
- int blinkFrequency = 0;
- BaseTimer timer;
- long counter;
- int allignment;
- public void setBlinkFrequency(int frequency)
- {
- blinkFrequency = frequency;
- }
- public void showNotify() {
- super.showNotify();
- if(blinkFrequency > 0)
- {
- timer = BaseTimer.schedule(100, 100, this, 0);
- }
- }
- public void hideNotify() {
- super.hideNotify();
- if(timer != null)
- {
- timer.cancel();
- timer = null;
- }
- }
- public ImageControl(Image image) {
- this.image = image;
- if(image != null)
- {
- setWidth(image.getWidth());
- setHeight(image.getHeight());
- }
- }
- public void setImage(Image img)
- {
- this.image = img;
- }
- public void paint(Graphics g) {
- if(blinkFrequency > 0)
- {
- if(counter % blinkFrequency == 0)
- return;
- }
- int xPos = 0;
- int yPos = 0;
- if( (allignment & Graphics.RIGHT) != 0 && image != null)
- {
- xPos = width - image.getWidth();
- }
- if( (allignment & Graphics.BOTTOM) != 0 && image != null)
- {
- yPos = height - image.getHeight();
- }
- if( (allignment & Graphics.HCENTER) != 0 && image != null)
- {
- xPos = (width - image.getWidth() )>> 1;
- }
- if( (allignment & Graphics.VCENTER) != 0 && image != null)
- {
- yPos = (height - image.getHeight()) >> 1;
- }
- if(image != null)
- g.drawImage(image, xPos, yPos, 0);
- }
- public void task(int data) {
- counter++;
- DisplayManager.getInst().invalidate();
- }
- public void setAllignment(int allignment) {
- this.allignment = allignment;
- }
- }