MainForm.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- package cardserver;
- /**
- * <p>Title: CardServer</p>
- *
- * <p>Description: lizhenpeng</p>
- *
- * <p>Copyright: Copyright (c) 2005</p>
- *
- * <p>Company: LP&P</p>
- *
- * @author lipeng
- * @version 1.0
- */
- import javax.microedition.lcdui.*;
- import javax.microedition.io.*;
- import java.util.*;
- public class MainForm
- extends Form implements CommandListener,Runnable
- {
- ServerSocketConnection server;
- SocketConnection clientSocket;
- Vector userList = new Vector();
- private Thread thread = null;
- boolean isRunning = false;
- static public MainForm inst;
- public MainForm()
- {
- super("服务器");
- this.append("服务器正在运行");
- try
- {
- server=(ServerSocketConnection)Connector.open("socket://:8070");
- isRunning=true;
- thread=new Thread(this);
- thread.start();
- }
- catch(Exception e)
- {
- }
- inst = this;
- }
- private void init()
- throws Exception
- {
- setCommandListener(this);
- addCommand(new Command("Exit",Command.EXIT,1));
- }
- public void commandAction(Command command,Displayable displayable)
- {
- if(command.getCommandType()==Command.EXIT)
- {
- CardServerMIDlet.quitApp();
- }
- }
- public void run()
- {
- while(isRunning)
- {
- try
- {
- clientSocket=(SocketConnection)server.acceptAndOpen();
- ClientConnection client = new ClientConnection(clientSocket);
- userList.addElement(client);
- new Thread(client).start();
- }
- catch(Exception e)
- {
- }
- }
- }
- }