在ArrayList中存储带参数的构造函数

时间:2014-03-02 22:36:44

标签: java

我有两节课。我们的想法是创建警报并将它们存储在一个数组中,以便稍后在JTable中显示它们。当我创建一个警报并且我想将它存储在数组中时,我卡住了。我需要帮助将它们添加到具有所有参数的数组中。

public class AlarmTester {

static ArrayList<Alarm> arr = new ArrayList<Alarm>();
public static void main(String[] args) {


  DateFormat todaysDate = new SimpleDateFormat("MMM d, yyyy");
    Calendar time = Calendar.getInstance();
    long milis = System.currentTimeMillis();

    Alarm a1 = new Alarm("Test", 700000, null, null, null, 0);
    Alarm a2 = new Alarm("Test2", System.currentTimeMillis(), null, null, null, 0);     


}

}

以下是方法

public class Alarm {
private String description;
private Calendar  endDay ,startTime, endTime;
private long startDay;
private int interval;

public Alarm(String d, long sd, Calendar ed ,Calendar st, Calendar et, int ri){
    description = d;
    startDay= sd; 
    endDay= ed;
    startTime= st;
    endTime = et;
    interval= ri;
}

public String getDescription(){
    return description;
}

public long getStartDay(){
    return startDay;
}

public Calendar getEndDay(){
    return endDay;
}

public Calendar getStartTime(){
    return startTime;
}

public Calendar getEndTime(){
    return endTime;
}

public int getInterval(){
    return interval;
}


// this method are for editing alarm

public void setDescription(String d){
    description= d;
}

public void setStartDay(long sd){
    startDay=sd;
}

public void setEndDay(Calendar ed){
    endDay=ed;
}

public void setStartTime(Calendar st){
    startTime=st; 
}

public void setEndTime(Calendar et){
    endTime=et;
}

public void setInterval(int ri){
    interval=ri;
}
}

测试人员

1 个答案:

答案 0 :(得分:0)

Alarm[] alarms = new Alarm[] {a1,a2};  

这会生成警报数组并添加2 警报