⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatmidlet.java

📁 <j2me 开发精解> 詹建光著 里所有的源码。对J2me的开发相当有帮助
💻 JAVA
字号:
package com.j2medev.ch6.socket;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ChatMIDlet extends MIDlet implements CommandListener{
    
    private Display display = null;
    private Form mainForm = null;
    private ChoiceGroup type = null;
    private Server server = null;
    private Client client = null;
    public static final String[] sc = {"服务器模式","客户端模式"};
    public static final Command startCommand = new Command("启动",Command.OK, 1);
    public static final Command exitCommand = new Command("退出",Command.EXIT,2);
    
    
    public void startApp() {
        if(display == null){
            display = Display.getDisplay(this);
            mainForm = new Form("选择模式");
            type = new ChoiceGroup("",Choice.EXCLUSIVE, sc, null);
            mainForm.append(type);
            mainForm.addCommand(exitCommand);
            mainForm.addCommand(startCommand);
            mainForm.setCommandListener(this);
        }
        display.setCurrent(mainForm);
        
    }
    
    public void setCurrent(Displayable displayable){
        display.setCurrent(displayable);
    }
    public void setCurrent(Alert alert,Displayable displayable){
        display.setCurrent(alert,displayable);
    }
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
        if(server != null){
            server.stop();
        }
        if(client != null){
            client.stop();
        }
    }
    
    public void commandAction(Command cmd,Displayable displayable){
        if(cmd == exitCommand){
            destroyApp(true);
            notifyDestroyed();
        }else if(cmd == startCommand){
            String label = type.getString(type.getSelectedIndex());
            if(label.equals(sc[0])){
                server = new Server(this);
                new Thread(server).start();
            }else if(label.equals(sc[1])){
                client = new Client(this);
                new Thread(client).start();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -