import javax.microedition.midlet.midlet;
import javax.microedition.midlet.midletstatechangeexception;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
public class imagegetter extends midlet implements commandlistener
{
private display display;
public static final command conncommand = new command("connect",
command.item, 1);
public static final command exitcommand = new command("exit", command.exit,
1);
private form mainform;
private getterthread gt;
protected void startapp() throws midletstatechangeexception
{
display = display.getdisplay(this);
mainform = new form("image getter");
mainform.append("click connect to get image");
mainform.addcommand(conncommand);
mainform.addcommand(exitcommand);
mainform.setcommandlistener(this);
display.setcurrent(mainform);
gt = new getterthread(this);
gt.start();
}
public void setimage(image image)
{
mainform.append(image);
display.setcurrent(mainform);
}
protected void pauseapp()
{
}
protected void destroyapp(boolean arg0) throws midletstatechangeexception
{
}
public void commandaction(command cmd, displayable disp)
{
if (cmd == conncommand)
{
synchronized (this)
{
notify();
}
} else if (cmd == exitcommand)
{
exitmidlet();
}
}
private void exitmidlet()
{
try
{
destroyapp(false);
notifydestroyed();
} catch (midletstatechangeexception e)
{
e.printstacktrace();
}
}
class getterthread extends thread
{
private imagegetter midlet;
public static final string url = "http://localhost/j2medev.png";
private httpconnection httpconn = null;
private inputstream is = null;
public getterthread(imagegetter midlet)
{
this.midlet = midlet;
}
public void run()
{
synchronized (midlet)
{
try
{
midlet.wait();
} catch (interruptedexception e)
{
e.printstacktrace();
}
}
system.out.println("connect to server...");
try
{
httpconn = (httpconnection) connector.open(url);
is = httpconn.openinputstream();
bytearrayoutputstream baos = new bytearrayoutputstream();
int ch = 0;
while ((ch = is.read()) != -1)
{
baos.write(ch);
}
byte[] imagedata = baos.tobytearray();
image image = image.createimage(imagedata, 0, imagedata.length);
midlet.setimage(image);
baos.close();
is.close();
httpconn.close();
} catch (ioexception e)
{
e.printstacktrace();
}
}
}
}
右键选择项目getimage-j2me-create obfuscated package,这样proguard就会把除midlet之外的class文件混淆。如下图所示:
在deploy文件夹内我们可以看到getimage.jar、getimage.jad和一些proguard产生的其他文件,你可以用jar命令解开getimage.jar,发现他的另一个class文件已经被混淆成a.class了,midlet类则没有任何改变,proguard除了混淆的功能之外同时会把我们的jar文件减小,提高一些运行效率。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器