爱技术

 找回密码
 注册会员

QQ登录

只需一步,快速开始

微信登录

微信扫一扫,快速登录

搜索
查看: 533|回复: 2
收起左侧

SXG75

[复制链接]
发表于 2008-11-9 20:56:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?注册会员 微信登录

x
在国外的网站上找到的
好像是JAVA的源代码


package cz.kruch.test;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.io.Connector;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.Item;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.Message;
import javax.wireless.messaging.TextMessage;
import java.io.IOException;

public final class CbsTestMIDlet extends MIDlet implements MessageListener, Runnable  {

    private MessageConnection connection;
    private Form form;
    private int count;

    protected void startApp() throws MIDletStateChangeException {
        Display display = Display.getDisplay(this);
        form = new Form("CBS Test");
        display.setCurrent(form);
        form.append(appendLine("Open channel..."));
        try {
            this.connection = (MessageConnection) Connector.open("cbs://:221", Connector.READ);
            this.connection.setMessageListener(this);
            form.append(appendLine("Waiting..."));
        } catch (Throwable t) {
            form.append(appendLine(t.toString()));
            display.setCurrent(new Alert("Error", t.toString(), null, AlertType.ERROR), form);
        }
    }

    protected void pauseApp() {
    }

    protected void destroyApp(boolean b) throws MIDletStateChangeException {
        // TODO quit politely
    }

    public void notifyIncomingMessage(MessageConnection messageConnection) {
        if (++count > 24) { // 24 msgs max - stop listening...
            try {
                this.connection.setMessageListener(null);
            } catch (IOException e) {
                // ignore
            }
        } else {
            (new Thread(this)).start();
        }
    }

    public void run() {
        try {
            Message message = connection.receive();
            if (message instanceof TextMessage) {
                form.append(appendLine("[" + ((TextMessage) message).getPayloadText() + "]"));
            } else {
                form.append(appendLine("[<binary msg>]"));
            }
        } catch (IOException e) {
            form.append(appendLine("[" + e.toString() + "]"));
        }
    }

    private Item appendLine(String line) {
        StringItem item = new StringItem(null, line);
        item.setLayout(Item.LAYOUT_2 | Item.LAYOUT_NEWLINE_AFTER);
        return item;
    }
}
 楼主| 发表于 2010-5-4 20:47:35 | 显示全部楼层
木有人鸟
回复 支持 反对

使用道具 举报

发表于 2010-5-5 15:41:27 | 显示全部楼层
 用来干嘛的?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员 微信登录

本版积分规则

小黑屋|Archiver|手机版|爱技术 ( 沪ICP备08115260号-3 )

GMT+8, 2024-5-29 04:49

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表