I have an issue with Java Arraylist: when I click the previous button it won't get the index of the last element.
Note: InfoStudent is a separate class that contains all student info like id, name and email; and arraylist student contains the info of the new students. I am not sure if my problem is the index like student.get (get the current student's id and minus 1 since index starts 0). My screenshot:

My code:
JButton btnFirst = new JButton("First");
btnFirst.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textFieldId.setText(Integer.toString(student.get(0).getId()));
textFieldName.setText(student.get(0).getName());
txtEmailbox.setText(student.get(0).getEmail());
}
});
btnFirst.setBounds(10, 215, 89, 22);
frame.getContentPane().add(btnFirst);
JButton btnPrev = new JButton("Prev");
btnPrev.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
current = Integer.parseInt(textFieldId.getText());
if(current== student.size()){
current= 0;
}
else {
current = current-1;
}
textFieldId.setText(Integer.toString(student.get(current).getId()));
textFieldName.setText(student.get(current).getName());
txtEmailbox.setText(student.get(current).getEmail());
//student.get(current).getId() is not working
}
});
btnPrev.setBounds(122, 215, 89, 22);
frame.getContentPane().add(btnPrev);
JButton btnNext = new JButton("Next");
btnNext.setBounds(230, 215, 89, 23);
frame.getContentPane().add(btnNext);
JButton btnLast = new JButton("Last");
btnLast.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textFieldId.setText(Integer.toString(student.get(student.size()-1).getId()));
textFieldName.setText(student.get(student.size()-1).getName());
txtEmailbox.setText(student.get(student.size()-1).getEmail());
}
});
btnLast.setBounds(329, 215, 89, 23);
frame.getContentPane().add(btnLast);
}
current = current -1;)? You should also address that case.ArrayListor even aListinterface in the code you posted.