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

📄 drawandfillexample.java

📁 Java ME手机应用开发大全一书的配套光盘上的源码
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class DrawAndFillExample extends MIDlet
{
  private Display  display; 
  private MyCanvas canvas; 
  public DrawAndFillExample ()
 {
	//获取MIDlet的Display对象实例
    display = Display.getDisplay(this);
	//声明Canvas屏幕对象
    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 DrawAndFillExample rectangleExample;
  public MyCanvas (DrawAndFillExample rectangleExample)
  {
    this.rectangleExample = rectangleExample;
    exit = new Command("Exit", Command.EXIT, 1);
    addCommand(exit);
    setCommandListener(this);
  } 
  protected void paint(Graphics graphics)
  {   
	  //设置画笔颜色为白色
      graphics.setColor(255,255,255);
	  //填充屏幕
      graphics.fillRect(0, 0, getWidth(), getHeight());
      //设置画笔颜色为红色
      graphics.setColor(255,0,0);
	  //绘制矩形图形
      graphics.drawRect(2, 2, 20, 20);
	  //绘制圆角矩形图形
      graphics.drawRoundRect(20, 20, 60, 60, 15, 45);  
	  //填充矩形图形
	  graphics.fillRect(40, 40, 20, 20);
	  //填充圆角矩形图形
      graphics.fillRoundRect(60, 60, 60, 60, 15, 45);  
	  //绘制直线
	  graphics.drawLine(90,180,160,100);
   }
  public void commandAction(Command command, Displayable displayable)
  {
    if (command == exit)
    {
     rectangleExample.exitMIDlet();
    }
  }
}

⌨️ 快捷键说明

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