日期:2014-05-20  浏览次数:20695 次

J2ME中static的功能
我把一个按钮可以用static声明,然后在两个面板上都加上这个按钮,不会造成冲突,然儿却不能把一个StringItem对象同时加两次,不管是在同一个面板或是同时加在不同的两个面板.
下面付了原码:
import   javax.microedition.midlet.*;
import   javax.microedition.lcdui.*;
import   java.util.*;

public   class   doubleS   extends   MIDlet   implements   CommandListener
{
          Display   display;
         
          Form   form1;
          Form   form2;
         
          StringItem   str1,strDate,strMem;
          static   StringItem   str2=new   StringItem( "The   Company   was   incorporated   on   May   1997   and   at   present   ,we   enjoy   monopoly   in   the   international   market   of   hardware   and   software   solutions ", " ");//用样式static声明的,但不可以被form1两次使用append(str2)
         
          static   Command   cmdExit=new   Command( "exit ",Command.EXIT,1);//static   方式声明的,可以被两个面板(form1&&form2)调用
          Command   cmdBack=new   Command( "back ",Command.BACK,2);
          Command   cmdOk=new   Command( "ok ",Command.OK,3);

          Ticker   ticket1,ticket2;

          public   doubleS()
          {  
                  Calendar   calendar=Calendar.getInstance();
                  String   date=Integer.toString(calendar.get(Calendar.MONTH)+1)+ "/ "+Integer.toString(calendar.get(Calendar.DAY_OF_MONTH))+ "/ "+Integer.toString(calendar.get(Calendar.YEAR));
                  strDate=new   StringItem( " ", "the   date: "+date+ ". ");
               
                  Runtime   runMemory=Runtime.getRuntime();
                 
                  String   total_mem=Long.toString(runMemory.totalMemory());
                  String   free_mem=Long.toString(runMemory.freeMemory());
                  strMem=new   StringItem( "0506010231 ", "the   total   memory   : "+total_mem+ "the   free   memory   : "+free_mem+ ". ");
           
               
          }
                   
          public   void   startApp()
          {
                             
                    str1=new   StringItem( "Welcome   to   Prosto   System ", " ");