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

📄 mycanvas.java

📁 用JavaME开发
💻 JAVA
字号:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;


class MyCanvas extends Canvas implements Runnable, CommandListener  {

	
	MainLet midplet;
	private Command send;
	private Command resend;
	
	
	
	/**
	 * 
	 */
	public MyCanvas(MainLet midplet) {
		this.midplet=midplet;
		new Thread(this).start();
		send=new Command("send",Command.SCREEN,1);
		resend=new Command("resend",Command.SCREEN,1);
		this.addCommand(send);
		this.addCommand(resend);
		this.setCommandListener(this);
	}

	protected void paint(Graphics g) {
		g.fillRect(0,0,getWidth(),getHeight());
		if(midplet.getIsSend()){
			g.drawString("send ok",0,0,Graphics.LEFT|Graphics.TOP);
		}else if(midplet.getIsSending()){
			g.drawString("sending.....",0,0,Graphics.LEFT|Graphics.TOP);
		}else{
			g.drawImage(midplet.getImage(),0,0,Graphics.LEFT|Graphics.TOP);
		}
	}
	
	public void run(){
		while(true){
			repaint();
			try{
				Thread.sleep(100);
			}catch(Exception e){System.out.println("sleep");}
		}
	}
	public void commandAction(Command c, Displayable arg1) {
		System.out.println("send");
		if(c==send){
			try{
				if(!midplet.getIsSending()){
					doSearch();
				}
			}catch(Exception e){e.printStackTrace();System.out.println("hahaha");}
		}
		else{
				if(c==resend){
					try{
						midplet.setIsSend(false);
						midplet.setIsSending(true);
						this.notifyAll();
					}catch(Exception e){System.out.println("en?");}
				}
			}
		
	}
	
	private synchronized void doSearch(){
		midplet.setIsSending(true);
		midplet.wakeUpConn();
		
	}

}

⌨️ 快捷键说明

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