Something like this, but of course with range checking added:
Code:
class Listener implements ActionListener
{
/*
Assuming you're using the same instance of
Listener for each control, otherwise this
variable will need to be static
*/
private int position = 0;
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("forward"))
{
position++;
}
else if (e.getActionCommand().equals("back"))
{
position--;
}
else
{
// whatever other commands you need
}
String str = list1.getItem(x);
t1.setText(str);
}
}
Bookmarks