爱技术

 找回密码
 注册会员

QQ登录

只需一步,快速开始

微信登录

微信扫一扫,快速登录

搜索
查看: 400|回复: 4
收起左侧

在国外的网站找到的SXG75的JAVA源代码

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

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

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

x
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;
    }
}
 楼主| 发表于 2008-12-3 10:34:25 | 显示全部楼层
难道没有人看么?
回复 支持 反对

使用道具 举报

发表于 2008-12-12 13:02:30 | 显示全部楼层

仔细看lZ的头像,嘻嘻

仔细看lZ的头像,嘻嘻
回复 支持 反对

使用道具 举报

发表于 2008-12-12 13:20:34 | 显示全部楼层
不搞开发的……不过lz你的头像有人看wap13::ii
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-12-12 14:27:01 | 显示全部楼层
鄙视楼上的!!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-24 21:00

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

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