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

📄 client.java

📁 J2ME书中重点教学程序
💻 JAVA
字号:
package src;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.SocketConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class Client extends MIDlet implements CommandListener
{
	private List list;
	
	private Command exit,ok;
	
	private Display display;
	
	private SocketConnection sConn;
	
	private InputStream is;
	private OutputStream os;
	
	private AcceptMessage acceptmes;
	
	public Client()
	{
		list = new List("信息发布系统", List.IMPLICIT);
		
		list.append("察看信息", null);
		list.append("写信息", null);
		
		exit = new Command("exit",Command.EXIT,1);
		ok = new Command("进入",Command.OK,1);
		
		list.addCommand(exit);
		list.addCommand(ok);
		
		list.setCommandListener(this);
		
		display = Display.getDisplay(this);
		
		/*try 
		{
			sConn = (SocketConnection)(Connector.open("socket://localhost:6000"));
			
			is = sConn.openInputStream();
			os = sConn.openOutputStream();
			
			acceptmes = new AcceptMessage(this);
			
			acceptmes.start();
			
		} 
		catch (IOException e) 
		{
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}*/
		// TODO 自动生成构造函数存根
	}
	
	public void showList(List x)
	{
		display.setCurrent(x);
	}
	
	public InputStream getIn()
	{
		return is;
	}
	
	public OutputStream getOut()
	{
		return os;
	}
	
	public void show()
	{
		display.setCurrent(list);
	}

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

	}

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

	}

	protected void startApp() throws MIDletStateChangeException
	{
		display.setCurrent(list);
		// TODO 自动生成方法存根

	}

	public void commandAction(Command command, Displayable arg1)
	{
		String lab = command.getLabel();
		
		if(lab.equals("exit"))
		{
			try
			{
				this.destroyApp(false);
				this.notifyDestroyed();
			}
			catch (MIDletStateChangeException e)
			{
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
			
		}
		
		if(lab.equals("进入"))
		{
			int index = list.getSelectedIndex();
			
			if(index==0)
			{
				List temp = acceptmes.getList();
				display.setCurrent(temp);
			}
			
			if(index==1)
			{
				SendMessage sm = new SendMessage(display,this);
			}
		}
		
		// TODO 自动生成方法存根
		
	}

}

⌨️ 快捷键说明

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