I'm having difficulty understanding how to create a copy method for a custom modellist. My goal is this: I have an arraylist that displays how many objects are in it. I created another list for the purpose of serving a temporary action. Basically, I have two tables. The first table are all my available items. My second table will contain the objects that I add to it for that temporary action, in this case, I'm simulating a match. After the simulation is complete, I can either add or remove which ever object I would like. What I don't have as a result of having a custom model list are the methods for removing an index from that temporary list. I have added the following code and thank you for helping :)
addPlayerMatch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
ArrayList<Human> testDM = new ArrayList<Human>();
try {
testDM.addHuman((//selected Index from first list////.getModel(//this method don't work//));
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
});
Here is my default model:
public class HumanListModel extends DefaultListModel implements TableModel{
private ArrayList<Human> data;
public HumanListModel()
{
super();
data = new ArrayList<Human>();
}
public void addHuman(Human h)
{
// add new human to the model
data.add(h);
}
public void removeHuman(Human h)
{
data.remove(h);
}
public int getColumnCount()
{
// the number of columns you want to display
return 1;
}
public int getRowCount()
{
return data.size();
}
public Object getValueAt(int row, int col)
{
return (row < data.size()) ? data.get(row) : null;
}
public String getColumnName(int col)
{
return "Human";
}
public Class getColumnClass(int col)
{
return Human.class;
}
public void addTableModelListener(TableModelListener arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean isCellEditable(int arg0, int arg1) {
// TODO Auto-generated method stub
return false;
}
@Override
public void removeTableModelListener(TableModelListener arg0) {
// TODO Auto-generated method stub
}
@Override
public void setValueAt(Object arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
}