package client;
import javax.microedition.lcdui.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.InputStream;
public class MainPanel implements CommandListener, ItemCommandListener {
//Main MIDlet
private MainMIDlet let = null;
//显示管理器
private Display display = null;
private Form mainForm = null;
private Command cmdExit = null;
private TextField sendText = null;
private StringItem buttonText = null;
private Image sendImage = null;
private StringItem buttonImage = null;
//-------------------------------------------------------------------------
public MainPanel(MainMIDlet __let) {
let = __let;
//获取显示管理器
display = Display.getDisplay(__let);
//Create main form
mainForm = new Form("Datagram Client");
//Create commands
cmdExit = new Command("Exit", Command.EXIT, 1);
sendText = new TextField("Message", null, 4096, TextField.ANY);
buttonText = new StringItem("Send Text", null, Item.BUTTON);
buttonText.setDefaultCommand(new Command("SendText", Command.ITEM, 1) );
buttonText.setItemCommandListener(this);
try {
sendImage = Image.createImage("/map.PNG");
}
catch (IOException e) {
sendImage = null;
e.printStackTrace();
}
buttonImage = new StringItem("Send Image", null, Item.BUTTON);
buttonImage.setDefaultCommand(new Command("SendImage", Command.ITEM, 1) );
buttonImage.setItemCommandListener(this);
//设置命令响应
mainForm.addCommand(cmdExit);
mainForm.setCommandListener(this);
mainForm.append(sendText);
mainForm.append(buttonText);
mainForm.append(new ImageItem("CAUTION: Image's size can't exceed 8kb!",
sendImage, Item.LAYOUT_NEWLINE_BEFORE | Item.LAYOUT_LEFT, null) );
mainForm.append(buttonImage);
buttonText.setLayout(Item.LAYOUT_CENTER);
buttonImage.setLayout(Item.LAYOUT_CENTER);
display.setCurrent(mainForm);
}
//-------------------------------------------------------------------------
public void commandAction(Command c, Displayable d) {
if(c == cmdExit) {
let.exit();
}
}
//-------------------------------------------------------------------------
public void commandAction(Command c, Item item) {
if(c.getLabel().equals("SendText") ) { //发送文本
try {
byte[] raw = sendText.getString().getBytes("UTF-8");
byte[] data = new byte[raw.length + 1];
data[0] = 0; //Text type
System.arraycopy(raw, 0, data, 1, raw.length);
new ClientThread(data).start();
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
if(c.getLabel().equals("SendImage") ) //发送图片
{
try {
InputStream imageStream = getClass().getResourceAsStream("/map.PNG");
byte[] data = new byte[imageStream.available() + 1];
data[0] = 1; //Image type
imageStream.read(data, 1, imageStream.available() );
imageStream.close();
new ClientThread(data).start();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
//-------------------------------------------------------------------------
};
没有合适的资源?快使用搜索试试~ 我知道了~
ch4.rar_j2me 网络
共28个文件
class:14个
java:7个
jad:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 34 浏览量
2022-09-14
17:39:58
上传
评论
收藏 30KB RAR 举报
温馨提示
j2me的网络通信,使用了http请求通信模式,还有数据报的通信
资源推荐
资源详情
资源评论
收起资源包目录
ch4.rar (28个子文件)
ch4
.eclipseme 238B
bin
client
ClientThread.class 2KB
MainMIDlet.class 778B
MainPanel.class 4KB
server
ServerThread.class 4KB
MainMIDlet.class 778B
MainPanel.class 2KB
common
DatagramUtilities.class 420B
deployed
res
.settings
org.eclipse.jdt.core.prefs 208B
src
client
MainPanel.java 3KB
MainMIDlet.java 816B
ClientThread.java 2KB
server
MainPanel.java 1KB
MainMIDlet.java 816B
ServerThread.java 3KB
common
DatagramUtilities.java 192B
.project 535B
.eclipseme.tmp
verified
classes
client
ClientThread.class 2KB
MainMIDlet.class 778B
MainPanel.class 4KB
server
ServerThread.class 4KB
MainMIDlet.class 778B
MainPanel.class 2KB
common
DatagramUtilities.class 420B
libs
emulation
ch4.jar 8KB
ch4.jad 208B
.classpath 242B
ch4.jad 185B
共 28 条
- 1
资源评论
小贝德罗
- 粉丝: 70
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功