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

📄 gamestart.java

📁 J2ME程序:手动设置URL主机地址和端口
💻 JAVA
字号:
import java.io.IOException;
import java.util.Vector;

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

public class gameStart extends MIDlet implements CommandListener,Runnable {
        public Alert logo; 
        public Form about;
        public List menu;  
        public Display display;
        public Command c1,c2;  
        public Command cback;  
        public static  gameStart midlet;
        public Connection1 connection1;
        public Login login;
        public Register register;
        public Messageshow message;
   
        Thread MainThread;
        public long UserID;
        public Form gameLoginForm;	
    	public TextField gameUserName2;			
    	public TextField gameUserPassword2;		
    	public Command LogOnConfirmCommand;		
    	public Command LogOnReturnCommand;			
    	public String UserName2 = ""	;		
    	public String UserPassword2= "";	
    
    	public Form gameRegisterForm; 			
    	public TextField gameUserName1;			
    	public TextField gameUserPassword1;		
    	public TextField url1,url2;
    	public TextField port1,port2;		
    	public Command RegisterConfirmCommand;	
    	public Command RegisterReturnCommand;	
    	public String UserName1 = ""	;			
    	public String UserPassword1= "";
    	Command urlok1,exit1;
    	
    	public Form messageInputForm;
		public TextField messageTextFierld;
		public Command MessageSend;
		public Command MessageBack;
    
		public String url = ""	;		
		public String port= "";	
		public String url3 = ""	;	
		public String port3= "";	
		

    
        public gameStart()
         {midlet=this;
         display=Display.getDisplay(this);
         logo=new Alert("mobile conference");
         logo.setTimeout(2500);
         Image im=loadImage("/welcome.png");
         logo.setImage(im);
         logo.setType(AlertType.INFO);
         c1=new Command("OK",Command.OK,1);
         c2=new Command("BACK",Command.BACK,1);
         String aboutInfo="mobile conference-test edition";
         about=new Form("ABOUT");
         about.append(aboutInfo);
         about.addCommand(c2);
         about.setCommandListener(this);
         

         menu=new List("MOBILE CONFERENCE",List.IMPLICIT);
         menu.addCommand(c1);
         menu.append("REGISTER",null);
         menu.append("LOGIN",null);
         menu.append("ABOUT",null);
         menu.append("EXIT",null);
         menu.setCommandListener(this);
          
         
        gameUserName2 = new TextField("User ID:",UserName2,10,TextField.ANY);
 		gameUserPassword2 = new TextField("Password: ",UserPassword2,10,TextField.PASSWORD);
 		LogOnConfirmCommand = new Command("OK",Command.OK,2);
 		gameLoginForm = new Form("LOGIN");
 		gameLoginForm.append(gameUserName2);
 		gameLoginForm.append(gameUserPassword2);
 		gameLoginForm.addCommand(LogOnConfirmCommand);
 		gameLoginForm.addCommand(c2);
 		gameLoginForm.setCommandListener(this);
 		url2 = new TextField("URL: ",url3,20,TextField.ANY);
		port2 = new TextField("PORT:",port3,5,TextField.NUMERIC);
		gameLoginForm.append(url2);
		gameLoginForm.append(port2);
 		
         
 		gameUserName1 = new TextField("User ID:",UserName1,10,TextField.ANY);
		gameUserPassword1 = new TextField("Password: ",UserPassword1,10,TextField.PASSWORD);
		RegisterConfirmCommand = new Command("OK",Command.OK,2);
		gameRegisterForm = new Form("REGISTER");
		gameRegisterForm.append(gameUserName1);
		gameRegisterForm.append(gameUserPassword1);
		gameRegisterForm.addCommand(RegisterConfirmCommand);
		gameRegisterForm.addCommand(c2);
		gameRegisterForm.setCommandListener(this);
		url1 = new TextField("URL: ",url,20,TextField.ANY);
		port1 = new TextField("PORT:",port,5,TextField.NUMERIC);
		gameRegisterForm.append(url1);
		gameRegisterForm.append(port1);
		
		
		messageInputForm = new Form("input message here:"+UserName2);
		messageTextFierld = new TextField(null,"",100,TextField.ANY);
		messageInputForm.append(messageTextFierld);
		MessageSend = new Command("SEND",Command.OK,1);
		MessageBack=new Command("EXIT",Command.BACK,1);
		messageInputForm.addCommand(MessageSend);	
		messageInputForm.addCommand(MessageBack);
		messageInputForm.setCommandListener(this);
		        
        MainThread = new Thread(this);	
        register = new Register(this);
        login = new Login(this);
        connection1 = new Connection1(this);
        message = new Messageshow(this);
  
        }
   public static Image loadImage(String fname)
   { Image im=null;
     try{
      im=Image.createImage(fname);
     }catch(Exception e){
      System.out.println("pic err fname="+fname);
     }
     return im;
   }
   public void startApp()
   {
            display.setCurrent(logo,menu);
   }
   public void pauseApp()
   {}
 

   public void commandAction(Command arg0, Displayable arg1) {
        if(arg0==c1)
        {      
                if(menu.getString(menu.getSelectedIndex()).equals("REGISTER"))
                {  
                	 display.setCurrent(gameRegisterForm); 
                   
                }
                if(menu.getString(menu.getSelectedIndex()).equals("ABOUT"))
                {	 
                      display.setCurrent(about);
                }
                if(menu.getString(menu.getSelectedIndex()).equals("LOGIN"))
                {   
                	
                      display.setCurrent(gameLoginForm); 
              
                }
                if(menu.getString(menu.getSelectedIndex()).equals("EXIT"))
                {  
                	this.notifyDestroyed();
                }

                }
     
        if(arg0==c2)
        {
                this.display.setCurrent(menu);
        }
       
      
        if(arg0==RegisterConfirmCommand)
        {       url=url1.getString();
                port=port1.getString();
        	    UserName1 = gameUserName1.getString();
               UserPassword1 = gameUserPassword1.getString();
               if(UserName1.length() <= 0){
     	       display.setCurrent(new Alert("Warning","please complete the ID!",null,AlertType.ERROR));
              	return; }
               if(UserPassword1.length() <= 0){
     	       display.setCurrent(new Alert("Warning","please complete the PASSWORD!",null,AlertType.ERROR));
     	       return;}
               
               register.rt.start();    
        } 
        if(arg0==LogOnConfirmCommand)
        { 
        	 url3=url2.getString();
             port3=port2.getString();	
        	UserName2 = gameUserName2.getString();
 		    UserPassword2 = gameUserPassword2.getString();
 		    if(UserName2.length() <= 0){
 			display.setCurrent(new Alert("Warning","please complete the ID!",null,AlertType.ERROR));
 			return;
 	      	}
 		    if(UserPassword2.length() <= 0){
 			display.setCurrent(new Alert("Warning","please complete the PASSWORD!",null,AlertType.ERROR));
 			return;}
            login.t.start();        
             }     

        if(arg0==MessageSend)
        {
        	if(messageTextFierld.getString().length() <= 0){
				display.setCurrent(new Alert("Warning","You can't send a blank",null,AlertType.ERROR));
			}else{
			connection1.SendOneData("55"+UserName2+","+messageTextFierld.getString());
			messageTextFierld.setString(""); }
         }
        if(arg0==MessageBack){
        	connection1.SendOneData("10"+UserName2);
        	this.notifyDestroyed();
       
        }
 }
   
public void run() {
	String inputStr="";
	int order;
	while (true) {
		inputStr = connection1.getOneData();    
		order = Integer.parseInt(connection1.getOneData().substring(0,2));
		System.out.println("this is get  data inputStr = "+inputStr);
		order = Integer.parseInt(inputStr.substring(0, 2));             
		System.out.println("this is get data order = "+order);
		inputStr = inputStr.substring(2, inputStr.length());
		switch (order) {
	    case 55: 
	   
		display.setCurrent(new Alert("system message","massage is already sent!",null,AlertType.ERROR));
		
		
			 break;
		}
	}
}


public void initMenu(){
	  this.display.setCurrent(menu);
}

public  String[] split(String str, String pre) {
	Vector veTmp = new Vector();
	while (str.indexOf(pre) != -1) {
		veTmp.addElement(str.substring(0, str.indexOf(pre)));
		str = str.substring(str.indexOf(pre) + 1, str.length());
	}
	if (veTmp.size() == 0) {
		return null;
	}
	String arrTmp[] = new String[veTmp.size()];
	for (int i = 0; i < arrTmp.length; i++) {
		arrTmp[i] = (String) veTmp.elementAt(i);
	}
	veTmp = null;
	return arrTmp;
}


public String[][] split(String str, String pre, int col) {
	Vector veTmp = new Vector();
	while (str.indexOf(pre) != -1) {
		veTmp.addElement(str.substring(0, str.indexOf(pre)));
		str = str.substring(str.indexOf(pre) + 1, str.length());
	}

	if (veTmp.size() == 0) {
		return null;
	}

	String arrTmp[][] = new String[veTmp.size() / col][col];
	int n = 0;
	for (int i = 0; i < arrTmp.length; i++) {
		for (int j = 0; j < col; j++) {
			arrTmp[i][j] = (String) veTmp.elementAt(n);
			n++;
		}
	}
	veTmp = null;
	return arrTmp;
}

public void Clear(){

		gameUserName1 = null;
		gameUserPassword1 = null;
		gameUserName2 = null;
		gameUserPassword2 = null;
		RegisterConfirmCommand = null;
		RegisterReturnCommand = null;
		gameRegisterForm = null;}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
	connection1.SendOneData("10"+UserName2);
	this.notifyDestroyed();
}
	
}

⌨️ 快捷键说明

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