⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mutableimageexample.java

📁 Java ME手机应用开发大全一书的配套光盘上的源码
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MutableImageExample extends MIDlet
{
  private Display  display;     
  private MyCanvas canvas;   
  public MutableImageExample ()
  {
    display = Display.getDisplay(this);
    canvas  = new MyCanvas (this);
  }
  protected void startApp()
  {
    display.setCurrent( canvas );
  }
  protected void pauseApp()
  { 
  }
  protected void destroyApp( boolean unconditional )
  { 
  }
  public void exitMIDlet()
  {
    destroyApp(true);
    notifyDestroyed();
  }
  class MyCanvas extends Canvas implements CommandListener
  {
    private Command exit;  
    private MutableImageExample mutableImageExample;
    private Image image = null;
    public MyCanvas(MutableImageExample mutableImageExample)
    {
      this. mutableImageExample = mutableImageExample;
      exit = new Command("Exit", Command.EXIT, 1);
      addCommand(exit);
      setCommandListener(this);
      try
      {
		 //声明一个可变图像,并初始化这个图像
        image = Image.createImage(70, 70);
		//获得访问可变图像的Graphics对象
        Graphics graphics = image.getGraphics();
		//设置画笔颜色
        graphics.setColor(255, 0, 0);
		//在可变图像中填充圆弧
        graphics.fillArc(10, 10, 60, 50, 180, 180);  
      }
      catch (Exception error)
      {
		 //显示创建可变图像错误信息
        Alert alert = new Alert("绘制失败","创建不变图像", null, null);
        alert.setTimeout(Alert.FOREVER);
        display.setCurrent(alert);
      }    
    } 
    protected void paint(Graphics graphics)
    {
      if (image != null)
      {
		//清屏操作
       graphics.setColor(255,255,255);
       graphics.fillRect(0, 0, getWidth(), getHeight());
	   //绘制可变图像
       graphics.drawImage(image, 30, 30, 
                    Graphics.VCENTER | Graphics.HCENTER);
      }
    }
    public void commandAction(Command command, Displayable display)
    {
      if (command == exit)
      {
        mutableImageExample.exitMIDlet();
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -