J2me MyLogger

本文介绍了一个简单的日志记录器类MyLogger,该类实现了CommandListener和ItemStateListener接口,用于在移动设备上显示和管理应用的日志信息。日志记录器可以根据设置开关选择是否启用,并能通过命令操作实现日志显示、关闭和清空等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.lcdui.Item; import javax.microedition.lcdui.ItemStateListener; public class MyLogger implements CommandListener, ItemStateListener { private MainCanvas mc = null; // if (MyLogger.LOGGER_ON) { // if (keyCode == Canvas.KEY_NUM9) { // if (!MyLogger.showingLog) { // Display.getDisplay(mainMIDlet).setCurrent(MyLogger.logForm); // } // } // } /** * * new MyLogger(maincanvas); * * * * * 是否日志打开 */ public static boolean LOGGER_ON = true; public static boolean showingLog = false; public static Form logForm = null; public static void Log(String logText) { if (LOGGER_ON) { logForm.append(logText); logForm.append("/n"); } } public void commandAction(Command command, Displayable displayable) { if (LOGGER_ON) { if (command.getCommandType() == Command.OK) { Display.getDisplay(mc.mainMIDlet).setCurrent(mc); mc.setFullScreenMode(true); showingLog = false; } else if (command.getCommandType() == Command.STOP) { logForm.deleteAll(); } return; } } public void itemStateChanged(Item item) { if (logForm.isShown()) { Display.getDisplay(mc.mainMIDlet).setCurrent(MyLogger.logForm); } } public MyLogger(MainCanvas aMc) { mc = aMc; if (LOGGER_ON) { logForm = new Form(""); logForm.setTitle("日志"); logForm.addCommand(new Command("确认", Command.OK, 1)); logForm.addCommand(new Command("清除", Command.STOP, 2)); logForm.setCommandListener(this); logForm.setItemStateListener(this); } } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值