我的记事本项目之路(二)

来源:互联网 发布:ug三维制图软件 编辑:程序博客网 时间:2024/04/28 13:17

        做好登陆界面之后,接下来就是记事本的主体了!首先,根据java面向对象的思想,记事本对象可以给它设置一个Note类,这样做的好处是:能够将Note()类封装起来,调用的时候只能通过get()和set()方法调用,大大的增加了安全性,Note.java代码如下:

package com.example.jishiben;

import java.io.Serializable;

public class Note implements Serializable {

    private int id;
    private String date;
    private String type;
    private String  introduction = "";
    
    public Note() {
        
    }
    
    public Note(int id, String date, String type, String introduction) {
        super();
        this.id = id;
        this.date = date;
        this.type = type;
        this.introduction = introduction;
    }
    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getIntroduction() {
        return introduction;
    }
    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

}

记事本的话,肯定还需要显示时间,这样才能根据事件的时间先后顺序进行排序,这里建一个时间工具类DateUtil.java,功能是获取系统的当前时间,并按照需要的格式进行格式化.代码如下:

package com.example.jishiben;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    
    public static String formatDate(long time) {
        Date date = new Date(time);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return sdf.format(date);
    }
    
}

预知后事如何,请听下回分解.

1 0
原创粉丝点击