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

📄 tools.java

📁 用J2ME 的手机贪吃蛇游戏源代码蛇头不能碰到蛇尾 吃点东西蛇身增长
💻 JAVA
字号:
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public abstract class Tools 
{
	public static void paintImage(Graphics g,Image im ,int x,int y,int ix,int iy,int w,int h)
	{
		g.setClip(x,y,w,h);
		g.drawImage(im,x-ix,y-iy,0);
		g.setClip(0,0,500,500);
	}
	
	public static byte[] toByte(int n)//int转换成byte[]
	{
		byte[] r=null;
		ByteArrayOutputStream bos=new ByteArrayOutputStream();
		DataOutputStream dos=new DataOutputStream(bos);
		try {
			dos.writeInt(n);
			r=bos.toByteArray();
			dos.close();
			bos.close();
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
		return r;
	}
	public static int toInt(byte[] b)
	{
		int r=0;
		ByteArrayInputStream bis=new ByteArrayInputStream(b);
		DataInputStream dis=new DataInputStream(bis);
		try {
			r=dis.readInt();
			dis.close();
			bis.close();
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
		return r;
	}
}
//import java.io.ByteArrayInputStream;
//import java.io.ByteArrayOutputStream;
//import java.io.DataInputStream;
//import java.io.DataOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//
//import javax.microedition.lcdui.Graphics;
//import javax.microedition.lcdui.Image;
//public class Tools
//{
//	public static void paintImage(Graphics g,Image im,int x,int y,int ix,int iy,int w,int h)
//	{
//		g.setClip(x,y,w,h);
//		g.drawImage(im,x-ix,y-iy,0);
//		g.setClip(0,0,500,500);
//	}
//	public static void writeInt(int n,OutputStream os)
//	{
//		byte [] data ;
//		ByteArrayOutputStream bos=new ByteArrayOutputStream() ;//先申请
//		DataOutputStream dos=new DataOutputStream (bos) ;//后申请
//		try {
//			dos.writeInt(n) ;
//			data=bos.toByteArray() ;
//			os.write(data) ;
//			dos.close() ;//先关闭
//			bos.close() ;//后关闭
//			
//		} catch (IOException e) {
//			
//			e.printStackTrace();
//		}
//		
//	}
//	public static int readInt(InputStream is)
//	{
//		int s = 0;
//		byte [] data=new byte [4] ;//一字符=4字节
//		try {
//			is.read(data) ;
//			ByteArrayInputStream bis=new ByteArrayInputStream(data) ;
//			DataInputStream dis=new DataInputStream(bis) ; 
//			s=dis.readInt();
//			dis.close() ;
//			bis.close() ;
//		} catch (IOException e) {
//			
//			e.printStackTrace();
//		}
//		return s;
//		
//		
//		
//	}
//}

⌨️ 快捷键说明

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