norains的专栏

只专注于WINCE开发

用户操作
[即时聊天] [发私信] [加为好友]
norainsID:norains
142878次访问,排名598,好友0人,关注者53人。
代码其实是一种乐趣
norains的文章
原创 189 篇
翻译 0 篇
转载 10 篇
评论 274 篇
norains的公告
联系方式请看置顶文章
最近评论
dfdf:讨厌MFC!我觉得MFC就是太乱了!看似无用的代码不要不行,MD微软啥都给我们做完了,原理性的东西我们却永远没法搞懂了!
ironox:有个地方 我觉得很别扭,不知道怎么办好

比如说 CReg reg(HKEY_CURRENT_USER,TEXT("ControlPanel\Volume"));
ControlPanel\Volume 有可能不存在呀,这个该怎么处理哦?对象虽然创建了,出错了也没提示
szterry:呵呵,果然工作狂技术狂,同感,一样的感觉……不过我才刚毕业一年……搞IT就是玩……
jinlking:这个botton的实现只是在主窗口画了一块区域,对于事件的处理还要放在主窗口的窗口处理函数之中,在对应的消息处理上调用CheckTap来判断是否是此“按钮”,问一下,这种方法与把按钮封装在子窗口中有什么区别,二者使用那个更好?
KUODY:博主真是好人
文章分类
收藏
    相册
    动漫
    文章图片
    程序交流
    xumercury的BLOG
    狗友们的博客
    清蒸石斑鱼
    美女如刀锋
    茁茁的BLOG
    魅力老姐的窝
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 NotePad完整源代码收藏

    新一篇: TestLatency反应测试游戏完整源代码 | 旧一篇: 漫谈WinCE的手写识别技术(二)

        J2ME版本的记事本,类似于西门子C65自带的便签.

    //---------------------------------------------------
    //ContentDataEntity.java
    //---------------------------------------------------
    package src;
    import java.io.*;
    public class ContentDataEntity 
    {
        
    public String title;
        
    public String date;
        
    public String text;

        
        
    public ContentDataEntity(String title,String date,String text)
        
    {
            
    this.title=title;
            
    this.text=text;
            
    this.date=date;
            
        }

        
        
    public ContentDataEntity()
        
    {}
        
        
    public byte[] encode()
        
    {
            
    byte[] bytData=null;
            
    try
            
    {
                ByteArrayOutputStream bos
    =new ByteArrayOutputStream();
                DataOutputStream dos
    =new DataOutputStream(bos);
                dos.writeUTF(title);
                dos.writeUTF(text);
                dos.writeUTF(date);            
                bytData
    =bos.toByteArray();
                dos.close();
                bos.close();
            }

            
    catch(Exception erro)
            
    {}        
            
    return bytData;
        }

        
        
    public void decode(byte[] data)
        
    {
            
    try
            
    {
                ByteArrayInputStream bis
    =new ByteArrayInputStream(data);
                DataInputStream dis
    =new DataInputStream(bis);
                title
    =dis.readUTF();
                text
    =dis.readUTF();
                date
    =dis.readUTF();
                bis.close();
                dis.close();
            }

            
    catch(Exception erro)
            
    {}
        }

    }

     

    //------------------------------------------------------
    //CreatNewTextScreen.java
    //------------------------------------------------------
    package src;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import java.util.*;
    import javax.microedition.rms.*;
    public class CreatNewTextScreen extends Form implements CommandListener
    {    
        
    private Display display;
        
    private NotePadMIDlet MIDlet;
        
    private TextField titleField;
        
    private TextField textField;
        
    private DateField dateField;
        
    private int recordID;
        
    private boolean firstSave=true;
        
        
    public CreatNewTextScreen(Display display,NotePadMIDlet MIDlet)
        
    {
            
    super("新建记事");
            
    this.display=display;
            
    this.MIDlet=MIDlet;
            titleField
    =new TextField("标题:","",20,TextField.ANY);
            dateField
    =new DateField("日期",DateField.DATE);        
            dateField.setDate(
    new Date());//设定时间为当前时间
            textField=new TextField("正文","",140,TextField.ANY);
            
    this.append(titleField);
            
    this.append(dateField);
            
    this.append(textField);
            
    this.addCommand(new Command("保存",Command.OK,0));
            
    this.addCommand(new Command("返回",Command.OK,0));
            
    this.setCommandListener(this);
        }

        
        
    public void commandAction(Command c,Displayable s)
        
    {
            String cmd
    =c.getLabel();
            
    if(cmd.equals("保存"))
            
    {
                saveData();
            }

            
    else if(cmd.equals("返回"))
            
    {
                ListScreen listScreen
    =new ListScreen(display,MIDlet);
                display.setCurrent(listScreen);
            }

        }

        
        
    public void saveData()
        
    {
            String dbname
    ="NotePadDataBase";
            RecordStore rs
    =RMSUtil.openRSAnyway(dbname);
            
    try
            
    {
                
    if(rs==null)
                
    {
                    Alert al
    =new Alert("");
                    al.setType(AlertType.INFO);
                    al.setTimeout(
    5000);
                    al.setString(
    "打开数据库出错,请与我联系:norains@163.com");
                    
    this.addCommand(new Command("返回",Command.BACK,0));
                    display.setCurrent(al);
                }

                
    else
                
    {
                    Calendar cal
    =Calendar.getInstance();
                    cal.setTime(dateField.getDate());
                    String strDate
    =Integer.toString(cal.get(cal.YEAR))+""+Integer.toString(cal.get(cal.MONTH))+""+Integer.toString(cal.get(cal.DAY_OF_MONTH))+"日 ";
                    
    //String strTime=Integer.toString(cal.get(cal.HOUR_OF_DAY))+":"+Integer.toString(cal.get(cal.MILLISECOND))+":"+Integer.toString(cal.get(cal.SECOND));
                    ContentDataEntity writeData=new ContentDataEntity(titleField.getString(),strDate,textField.getString());
                    
    byte[] bytTemp=writeData.encode();
                    
    if(firstSave==true)
                    
    {
                        recordID
    =rs.addRecord(bytTemp,0,bytTemp.length);
                        firstSave
    =false;
                    }

                    
    else
                    
    {
                        rs.setRecord(recordID,bytTemp,
    0,bytTemp.length);
                    }

                    
    //如果加入数据出错,则会抛出异常,下面这段代码不执行
                    Alert al=new Alert("");
                    al.setString(
    "已经成功保存!");
                    al.setType(AlertType.INFO);
                    al.setTimeout(Alert.FOREVER);
                    display.setCurrent(al,
    this);
                }

                rs.closeRecordStore();
            }

            
    catch(Exception erro)
            
    {
                Alert al
    =new Alert("");
                al.setString(
    "出现错误,无法保存!请与我联系:norains@163.com");
                al.setType(AlertType.ERROR);
                al.setTimeout(Alert.FOREVER);
                display.setCurrent(al,
    this);
            }

        }

        
        
        
    }

    //-----------------------------------------------------
    //EditContentScreen.java
    //-----------------------------------------------------
    package src;

    import java.util.Calendar;
    import java.util.Date;

    import javax.microedition.lcdui.*;
    import javax.microedition.rms.*;

    public class EditContentScreen extends Form implements CommandListener
    {
        
    private Display display;
        
    private NotePadMIDlet MIDlet;
        
    private TextField titleField;
        
    private TextField textField;
        
    private DateField dateField;
        
    private String title;
        
    private String date;
        
    private String text;
        
    private int recordID;
        
        
    public EditContentScreen(Display display,NotePadMIDlet MIDlet,int ID)
        
    {
            
    super("新建记事");
            
    this.display=display;
            
    this.MIDlet=MIDlet;
            
    this.recordID=ID;
            readRecordData();
            titleField
    =new TextField("标题",title,20,TextField.ANY);
            dateField
    =new DateField("修改日期",DateField.DATE);        
            dateField.setDate(
    new Date());//设定时间为当前时间
            textField=new TextField("正文",text,140,TextField.ANY);
            
    this.append(titleField);
            
    this.append(dateField);
            
    this.append(textField);
            
    this.addCommand(new Command("保存",Command.OK,0));
            
    this.addCommand(new Command("返回",Command.OK,0));
            
    this.setCommandListener(this);
        }

        
        
    public void commandAction(Command c,Displayable s)
        
    {
            String cmd
    =c.getLabel();
            
    if(cmd.equals("保存"))
            
    {
                saveData();
            }

            
    else if(cmd.equals("返回"))
            
    {
                ViewListScreen viewListScreen
    =new ViewListScreen(display,MIDlet);
                display.setCurrent(viewListScreen);
            }

        }

        
        
    private void readRecordData()
        
    {
            String dbname
    ="NotePadDataBase";
            RecordStore rs
    =RMSUtil.openRSExisted(dbname);
            
    if(rs==null)
            
    {
                
    this.append("打开数据库失败!可能尚未储存数据,请进行游戏后再尝试.如果依然出现错误,请与我联系:norains@163.com");
            }

            
    else
            
    {    
                
    try
                
    {
                    ContentDataEntity recordData
    =new ContentDataEntity ();
                    recordData.decode(rs.getRecord(recordID));
                    title
    =recordData.title;
                    date
    =recordData.date;
                    text
    =recordData.text;                
                    rs.closeRecordStore();
                }

                
    catch(Exception erro)
                
    {}            
            }
        
        }

        
        
    public void saveData()
        
    {
            String dbname
    ="NotePadDataBase";
            RecordStore rs
    =RMSUtil.openRSAnyway(dbname);
            
    try
            
    {
                
    if(rs==null)
                
    {
                    Alert al
    =new Alert("");
                    al.setType(AlertType.INFO);
                    al.setTimeout(
    5000);
                    al.setString(
    "打开数据库出错,请与我联系:norains@163.com");
                    
    this.addCommand(new Command("返回",Command.BACK,0));
                    display.setCurrent(al);
                }

                
    else
                
    {
                    Calendar cal
    =Calendar.getInstance();
                    cal.setTime(dateField.getDate());
                    String strDate
    =Integer.toString(cal.get(cal.YEAR))+""+Integer.toString(cal.get(cal.MONTH))+""+Integer.toString(cal.get(cal.DAY_OF_MONTH))+"日 ";
                    
    //String strTime=Integer.toString(cal.get(cal.HOUR_OF_DAY))+":"+Integer.toString(cal.get(cal.MILLISECOND))+":"+Integer.toString(cal.get(cal.SECOND));
                    ContentDataEntity writeData=new ContentDataEntity(titleField.getString(),strDate,textField.getString());
                    
    byte[] bytTemp=writeData.encode();
                    rs.setRecord(recordID,bytTemp,
    0,bytTemp.length);
                    
                    
    //如果加入数据出错,则会抛出异常,下面这段代码不执行
                    Alert al=new Alert("");
                    al.setString(
    "已经成功保存!");
                    al.setType(AlertType.INFO);
                    al.setTimeout(Alert.FOREVER);
                    display.setCurrent(al,
    this);
                }

                rs.closeRecordStore();
            }

            
    catch(Exception erro)