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

📄 datagram_midlet.java

📁 运用HTTPCONNECTION做一个简单的聊天程序
💻 JAVA
字号:
package datagram003packet;

import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class Datagram_MIDlet extends MIDlet implements CommandListener {

	private Server s;
    private Guest g;
    private Form form;
    private ChoiceGroup cg;
    private Command exitCommand;
    private Command startCommand;
    private Display display;
    private  static boolean is_paused=false; 
    private static final String str_server="Server_Datagram";
    private static final String str_guest="Guest_Datagram";
    private DongHua dh;
    //
   public  static int count=0;
	public Datagram_MIDlet()
	{
		 form=new Form("Select_Applacation");
		 dh=new DongHua();
		 String []str_array={str_server,str_guest};
		 cg=new ChoiceGroup("Select",ChoiceGroup.EXCLUSIVE,str_array,null);
		 exitCommand=new Command("Exit",Command.EXIT,1);
		 startCommand=new Command("Start",Command.OK,1);
		 form.append(cg);
		 form.append(dh);
		  dh.startRun();
		 form.addCommand(exitCommand);
		 form.addCommand(startCommand);
		 form.setCommandListener(this);
		 display=Display.getDisplay(this);
	     display.setCurrent(form);
		
	}
	public boolean isPaused()
	{
		return is_paused;
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO 自动生成方法存根
		if(s!=null)
		{
			s.stop();
		}
		if(g!=null)
		{
		  g.stopRun();	
		}
	}

	protected void pauseApp() {
		// TODO 自动生成方法存根
		is_paused=true;

	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO 自动生成方法存根

	}

	public void commandAction(Command c, Displayable d) {
		// TODO 自动生成方法存根
		if(c==startCommand)
		{
			//if( cg.getSelectedIndex()==0)
			String str_temp=cg.getString(cg.getSelectedIndex());
			if(str_temp.equalsIgnoreCase("Server_Datagram"))
			{
				s=new Server(this);
				s.startRun();//induce the delay
			    dh.stopRun();
				
			}
			else if(str_temp.equalsIgnoreCase("Guest_Datagram"))
			{
			    g=new Guest(this);
				g.startRun();//induce the delay
				dh.stopRun();
				
			}
		}
		else if(c==exitCommand)
		{
			try
			{
				this.destroyApp(true);
				this.notifyDestroyed();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}

	}

}

⌨️ 快捷键说明

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