📄 mapclient.java
字号:
import javax.microedition.io.* ;
import javax.microedition.midlet.* ;
import javax.microedition.lcdui.* ;
import java.io.* ;
public class SocketConnent extends MIDlet implements CommandListener , Runnable
{
private Display display ;
private Form frm ;
private Command c1 ;
private Command c2 ;
private SocketConnection conn ;
private InputStream is ;
private OutputStream os ;
private DataInputStream dis ;
private DataOutputStream dos ;
public SocketConnent()
{
display = Display.getDisplay(this) ;
frm = new Form("Socket Test1") ;
c1 = new Command("Exit" , Command.EXIT , 0) ;
c2 = new Command("OK" , Command.OK , 0) ;
frm.addCommand(c1) ;
frm.addCommand(c2) ;
frm.setCommandListener(this) ;
}
public void startApp()
{
display.setCurrent(frm) ;
}
public void pauseApp()
{
}
public void destroyApp(boolean con)
{
}
public void commandAction(Command c , Displayable a)
{
if(c.getLabel() == "Exit")
{
destroyApp(true) ;
notifyDestroyed() ;
}
if(c.getLabel() == "OK")
{
Thread t1 = new Thread(this) ;
t1.start() ;
}
}
public void run()
{
conn = null ;
is = null ;
os = null ;
dis = null ;
dos = null ;
try
{
conn = (SocketConnection) Connector.open("socket://163.25.101.160:122") ;
is = conn.openInputStream() ;
dis = new DataInputStream(is) ;
int size = Integer.parseInt( dis.readUTF() ) ;
frm.append(Integer.toString(size)) ;
byte [] data = new byte[size] ;
//------------修改部分--------------------------------------------------------------------------------------------
int length = 0 ;
while(length < size)
{
final int read = dis.read( data , length , size - length) ;
if(read != -1)
length = length + read ;
else
break ;
}
//--------------------------------------------------------------------------------------------------------------
Image img = Image.createImage(data , 0 , size) ;
frm.append(img) ;
is.close() ;
dis.close() ;
conn.close() ;
}
catch(Exception e)
{
frm.append(e.toString()) ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -