小弟对于前不久刚学的JList、List和ArrayList不太熟练。我知道JList可以用DefaultListModel的addElement()放进元素。但是不懂如何将List和ArrayList的内容传到JList中显示?还有一个问题是:按照老师提示我写了一个ArrayList类用来存放Students类的信息,代码如下(后面查找的代码省略了):
public class StuArrayList{
private ArrayList<Students> stus;
public StuArrayList(){
stus=new ArrayList<Students>();
} public void add(Students stu){
stus.add(stu);
}
students类就只有stuId,stuName,stuSex的get,set方法和students的构造函数,没有别的代码了。
我在事件处理类中直接Students stus = new Students(id,name,sex);然后用ArrayList的add(stus);直接将那三个值存放在ArrayList中,这种做法对吗?
Students stus = new Students(id,name,sex);
sal.add(stus);
dlm.addElement((Object)sal.getStus());
lst.setModel(dlm);
我在事件处理类中是这样子写的,sal就是ArrayList,dlm就是DefaultListModel,最后在JList中显示出来的是[Students@xxxxxx]之类的东西。请各位帮我分析下,谢谢。
public class StuArrayList{
private ArrayList<Students> stus;
public StuArrayList(){
stus=new ArrayList<Students>();
} public void add(Students stu){
stus.add(stu);
}
students类就只有stuId,stuName,stuSex的get,set方法和students的构造函数,没有别的代码了。
我在事件处理类中直接Students stus = new Students(id,name,sex);然后用ArrayList的add(stus);直接将那三个值存放在ArrayList中,这种做法对吗?
Students stus = new Students(id,name,sex);
sal.add(stus);
dlm.addElement((Object)sal.getStus());
lst.setModel(dlm);
我在事件处理类中是这样子写的,sal就是ArrayList,dlm就是DefaultListModel,最后在JList中显示出来的是[Students@xxxxxx]之类的东西。请各位帮我分析下,谢谢。
return name; // modify
}
你想打印字符串,你必须覆盖Object的toString()方法自己重写。