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

📄 choiceqq.java

📁 蓝牙聊天,带表情! 自定义组件,美观,大方!
💻 JAVA
字号:
package com.bt;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

public class ChoiceQQ extends Canvas{
	
	private int screenWidth = 0;
	private int screenHeight = 0;
	private int choiceW = 0;
	private int choiceH = 0;
	private int choiceX = 0;
	private int choiceY = 0;
	private String CMD_OK = "确认";
	private Font font = null;
	public static String position = null;
	private int offset = 0;
	
	public static String getPosition() {
		return position;
	}

	public static void setPosition(String position) {
		ChoiceQQ.position = position;
	}

	public ChoiceQQ(){
		this.setFullScreenMode(true);
		screenWidth = this.getWidth();
		screenHeight = this.getHeight();
		choiceW = BTMIDlet.imgWidth;
		choiceH = BTMIDlet.imgHeight;
		font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
	}
	
	protected void paint(Graphics g) {
		// TODO Auto-generated method stub
		setFullScreenMode(true);
		g.setColor(0,230,190);
		g.fillRect(0, 0, screenWidth, screenHeight);
		for(int i=0,row=1,column=1;i<BTMIDlet.imgQQ.length;i++,column++){
			if(column%11==0){
				row++;
				column = 1;
			}
			g.drawImage(BTMIDlet.imgQQ[i], (screenWidth-10*BTMIDlet.imgWidth)/2+(column-1)*BTMIDlet.imgWidth, 
					(screenHeight-10*BTMIDlet.imgHeight)/2+(row-1)*BTMIDlet.imgHeight, 0);
		}
		drawChoiceRect(g);
		drawCMD(g);
	}
	
	private void drawChoiceRect(Graphics g){
		g.setColor(0xff0000);
		g.drawRect((screenWidth-10*BTMIDlet.imgWidth)/2+choiceX*choiceW-2,(screenHeight-10*BTMIDlet.imgHeight)/2+choiceY*choiceH-2, choiceW, choiceH);
	}
	
	private void drawCMD(Graphics g){
		g.setColor(200,231,0);
		g.fillRect(0, screenHeight-(font.getHeight()+2), screenWidth, font.getHeight()+2);
		g.setColor(0xffffff);
		g.drawLine(0, screenHeight-(font.getHeight()+2), screenWidth, screenHeight-(font.getHeight()+2));
		g.setColor(0x000000);
		g.setFont(font);
		g.drawString(CMD_OK, 2, screenHeight-(font.getHeight()+1), 0);
	}
	
	protected void keyPressed(int keyCode){
		if(getGameAction(keyCode)==1){		//上
			if(choiceY == 0){
				choiceY = 9;
				offset+=90;
			}else{
				choiceY--;
				offset-=10;
			}
		}else if(getGameAction(keyCode)==6){//下
			if(choiceY == 9){
				choiceY = 0;
				offset-=90;
			}else{
				choiceY++;
				offset+=10;
			}
		}else if(getGameAction(keyCode)==2){//左
			if(choiceX == 0){
				choiceX = 9;
				offset += 9;
			}else{
				choiceX--;
				offset--;
			}
		}else if(getGameAction(keyCode)==5){//右
			if(choiceX == 9){
				choiceX = 0;
				offset -= 9;
			}else{
				choiceX++;
				offset++;
			}
		}else if(getKeyName(keyCode).equals("SOFT1")||getGameAction(keyCode)==8){
			if(position.equals("Server")){
				new Thread(){
					public void run(){
						Server.btServer.chatMessage("自己",choiceQQ());
						Server.btServer.writeInfo(choiceQQ());
						BTMIDlet.display.setCurrent(Server.btServer);
					}
				}.start();
			}
			else{
				new Thread(){
					public void run(){
						Client.btClient.chatMessage("自己",choiceQQ());
						Client.btClient.writeInfo(choiceQQ());
						BTMIDlet.display.setCurrent(Client.btClient);
					}
				}.start();
			}
		}
		repaint();
	}
	
	public String choiceQQ(){
		if(offset == 99){
			return "没有此表情!";
		}else{
			return "<:="+offset+":>";
		}
	}

}

⌨️ 快捷键说明

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