`
micheal19840929
  • 浏览: 163205 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

J2ME中使用microlog

    博客分类:
  • J2ME
阅读更多

 

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

import net.sf.microlog.core.Logger;
import net.sf.microlog.core.LoggerFactory;
import net.sf.microlog.core.PropertyConfigurator;
public class Hello3D extends MIDlet implements CommandListener
{
  private Command exitCommand = new Command("Exit", Command.EXIT, 1);
  private Logger logger=LoggerFactory.getLogger(Hello3D.class);
  public void startApp()
  {
    PropertyConfigurator.configure("/microlog.properties"); //loads the configuration file
    Form mForm = new Form("Hello 3D Properties:");
    String s = new String();
    Font.getFont(0, 1, 8);
    mForm.append("\nM3G Version: ");
    mForm.append(s + System.getProperty("microedition.m3g.version"));//获取M3G版本属性
    mForm.addCommand(exitCommand);				//添加退出按钮
    mForm.setCommandListener(this);					//设置软键监听
    Display.getDisplay(this).setCurrent(mForm);			//显示Form
    
    logger.info("start");
  }
  public void pauseApp()  {  }
  public void destroyApp(boolean unconditional)  {  }
  public void commandAction(Command command, Displayable displayable)
  {
    if (command == exitCommand)					//当按下Exit软键则退出程序
    {
      destroyApp(true);
      notifyDestroyed();
    }
  }
}

microlog.properties

# Sets the level to log. See log4j documentation for a more in-depth discussion
microlog.level=DEBUG
#
# Comma seperated list of appenders. FileAppender was removed (no FS on SPOTs)
#   ConsoleAppender -- can only be viewed when SPOT client is connected via
#                      'ant run'
#   RecordStoreAppender -- stores log to record store, can be viewed by
#                      deploying and running the microlog jar file
#                      
#microlog.appender=net.sf.microlog.appender.RecordStoreAppender;net.sf.microlog.appender.ConsoleAppender;net.sf.microlog.midp.appender.FileConnectionAppender
microlog.appender=net.sf.microlog.appender.ConsoleAppender
# The maximum number of log entries to be held in the record store
#microlog.appender.RecordStoreAppender.maxLogEntries=500
# Note- time is only needed for console appender
# RecordStoreLogViewer will still display time without this variable set 
#
# The formatter to use
#   SimpleFormatter -- logs the debug level and message only
#   ConfigurableFormatter -- has the following options
#                      level     :  if true, logs the debug level
#                      message   :  if true, logs the debug message
#                      time      :  'date' to print entire date with message
#                                   'millis' to print time in milliseconds
#                                   NOTE: only needed for consoleviewer
#                                       date is always stored/viewed when
#                                       reading RMS log
#                      delimiter :  delimiter string between message parts
#microlog.formatter=net.sf.microlog.format.ConfigurableFormatter;
#microlog.formatter.ConfigurableFormatter.time=millis 
#microlog.formatter.ConfigurableFormatter.level=true 
#microlog.formatter.ConfigurableFormatter.message=true
#microlog.formatter.ConfigurableFormatter.delimiter=- 

# Set the pattern for the PatternFormatter
# microlog.formatter.PatternFormatter.pattern=%r %c %m %T
# This would print the relative logging time, the name of the Logger, the logged message and the Throwable object (if not null).
#
#  The available pattern conversions are:
# %c : prints the name of the Logger
# %d : prints the date (absolute time)
# %m : prints the logged message
# %P : prints the priority, i.e. Level of the message.
# %r : prints the relative time of the logging. (The first logging is done at time 0.)
# %t : prints the thread name.
# %T : prints the Throwable object.
# %% : prints the '%' sign.

microlog.appender=net.sf.microlog.core.appender.ConsoleAppender;
microlog.formatter=net.sf.microlog.core.format.PatternFormatter
microlog.formatter.PatternFormatter.name=MyFormatterName
microlog.formatter.PatternFormatter.pattern=%P [%d] %c--> %m %T

# End of file. Do not remove this line.

 

结果如下:

INFO [0] Hello3D--> start

分享到:
评论

相关推荐

    J2me中文教程 pdf

    J2me中文教程.pdf J2me中文教程.pdf

    J2ME中使用Socket开发联网程序

    介绍了J2ME中使用Socket进行网络连接

    J2ME中文教程J2ME中文教程J2ME中文教程

    1. **MIDlet**:J2ME应用程序的基本单元,类似于Java应用程序中的主类。 2. **Displayable**:用户界面的基本元素,包括Screen和Form。 3. **User Interface**:J2ME使用轻量级的GUI组件,如TextBox、ChoiceGroup和...

    J2ME中文输入Demo

    在J2ME中,使用Unicode编码处理中文字符至关重要,因为它能确保正确地存储和传输中文字符。 3. **输入法引擎** 中文输入法通常涉及到拼音输入、笔画输入或五笔字型等。在J2ME平台上,由于资源限制,拼音输入是最...

    J2ME 中文api以及应用 J2ME 中文api以及应用.rar

    这类文档通常会详细介绍每个类、方法和接口的用途,提供示例代码,并解释如何在实际项目中使用这些API。 **www.pudn.com.txt**可能是一个指向资源网站的链接或者说明文件,pudn.com是一个知名的中国技术资源分享...

    J2ME中文教程,J2ME手机程序开发

    本教程将深入讲解J2ME在手机程序开发中的应用,帮助开发者掌握这一核心技术。 ### J2ME技术概述 J2ME由两大部分构成:配置(Configurations)和框架(Profiles)。配置定义了运行时环境的基本特性,如内存大小和...

    J2ME用户使用手册(PDF)

    J2ME用户使用手册(PDF) J2ME用户使用手册(PDF)

    J2ME中文教程.pdf

    J2ME中文教程 不错的学习资料,刚开始学习的可以参考下!

    J2ME API 2.0 J2ME使用手册 J2ME帮助文档

    **J2ME API 2.0 - J2ME使用手册 - J2ME帮助文档** Java 2 Micro Edition(J2ME)是Java平台的一个子集,专为资源有限的设备如移动电话、智能手表和家用电器等设计。J2ME API 2.0 提供了在这些小型设备上开发应用...

    J2ME中文版教程 J2ME教程

    4. **MIDP API详解**:MIDP是J2ME中用于创建移动应用的核心API,教程会详细介绍如何使用Canvas、Form、Item等组件进行用户界面设计,以及怎样利用 MIDP的网络功能实现数据通信。 5. **图形与多媒体**:J2ME支持丰富...

    图片分类 J2ME中的图片处理

    【标题】:“图片分类 J2ME中的图片处理” 【描述】:“图片的特点及分类;png图片的格式分析;图片在J2me中的应用。” 【标签】:“图片处理” “J2ME” “png” 在Java的移动开发领域,J2ME(Java 2 Micro ...

    J2ME 中文教程1.01

    5. **MIDlet**:J2ME中的应用程序单元,类似于Java SE中的JApplet。一个MIDlet由一个主类(实现了MIDlet接口)和可选的其他类组成。 6. **用户界面(UI)编程**:J2ME的UI通常基于 Lightweight User Interface ...

    J2ME 中文教程 MIDP2.0

    MIDP(Mobile Information Device Profile)2.0是J2ME中的一个重要配置,它提供了在这些小型设备上开发应用程序的基本框架和API。本教程将深入探讨如何使用J2ME和MIDP2.0进行移动应用开发。 **1. J2ME架构** J2ME...

    J2ME中文教程

    在J2ME中,RecordStore是用于存储非结构化数据的主要机制。开发者可以创建、读取、更新和删除RecordStore中的记录。此外,FileConnection API允许开发者访问设备的文件系统,进行文件的读写操作。 **游戏开发** ...

    j2Me 实例 笔记源码

    5. **类与方法**:源码中可能包含对J2ME API的多种使用,如网络通信(利用HttpConnection和DataInputStream/OutputStream进行HTTP请求),文件I/O(FileConnection API),以及线程管理(Thread类)。 6. **事件...

    j2me点阵字库

    在J2ME开发中,使用点阵字库通常涉及到以下几个关键知识点: 1. **字库加载**:在J2ME程序启动时,需要加载点阵字库文件,这通常通过解析二进制或文本格式的字库数据来实现。开发者需要编写代码来读取字库文件,并...

    J2ME中文开发教程(附带Myeclipse用J2ME插件)

    Myeclipse中的J2ME插件,使得开发者可以直接在IDE中创建、编辑、构建和运行J2ME项目,大大提高了开发效率。 在使用Myeclipse进行J2ME开发时,你可以创建新的J2ME工程,配置所需的CLDC和MIDP版本,然后添加源代码...

    在eclipse中怎样使用j2me

    在eclipse中怎样使用j2me 在eclipse中怎样使用j2me 在eclipse中怎样使用j2me

    J2ME中文教程(包含代码)

    在J2ME中,数据存储通常使用Record Management System (RMS)。RMS提供了一个简单的键值对存储机制,适用于小规模的数据存储。开发者需要学会如何创建记录商店、记录和操作数据。 **J2ME的事件驱动模型** J2ME应用...

Global site tag (gtag.js) - Google Analytics