Hi guys, would appreciate some help here.

The below is part of the codes of my image matching programme. The programme loads 2 different series of images in the area and the up/down button is supposed to change each set of the series of images. Currently, the codes only allow one set of the images to be changed. Any idea what can be done so that both set get changes when the up/down key is pressed?

Thanks!

Codes:

public void keyReleased(KeyEvent e) {
zoom = false;
repaint();
}

public void keyPressed(KeyEvent e) {
System.out.println("" + e.getKeyCode());
switch (e.getKeyCode()) {
case 16:
zoom = true;
zoomPt = getMousePosition();
repaint();
break;
case 39:
loadImage(true, true);
break;
case 40:
loadImage(false, true);
break;
case 38:
loadImage(false, false);
break;
case 37:
loadImage(true, false);
break;
}

}
public void changeDir(File dir) {
this.dir = dir;
}
public void loadImage(boolean isFileA, boolean increase) {
File[] fileList = dir.listFiles(new FilenameFilter() {

public boolean accept(File dir, String name) {
if (name.toLowerCase().endsWith(".dcm")
|| name.toLowerCase().endsWith(".dc3")
|| name.toLowerCase().endsWith(".dic")) {
return true;
} else {
return false;
}
}
});
if (fileList.length < 2) {
return;
}
try {
if (isFileA) {
a_os = increase? (a_os + 1) % fileList.length : (a_os - 1 + fileList.length) % fileList.length;
} else {
b_os = increase? (b_os + 1) % fileList.length: (b_os - 1 + fileList.length) % fileList.length;
}
String ext = fileList[a_os].getName().substring(fileList[a_os].getName().lastIndexOf(".") + 1);
Iterator readers = ImageIO.getImageReadersByFormatName(ext);
ImageReader reader = (ImageReader) readers.next();
reader.setInput(new FileImageInputStream(fileList[a_os]), true);
imgA = ((DICOMImageReader) reader).read(0, null);

ext = fileList[b_os].getName().substring(fileList[b_os].getName().lastIndexOf(".") + 1);
readers = ImageIO.getImageReadersByFormatName(ext);
reader = (ImageReader) readers.next();
reader.setInput(new FileImageInputStream(fileList[b_os]), true);
imgB = ((DICOMImageReader) reader).read(0, null);

w = Math.max(imgA.getWidth(), imgB.getWidth());
h = Math.max(imgA.getHeight(), imgB.getHeight());
} catch (Exception e) {
String fileName;
fileName = isFileA ? fileList[a_os].getPath() : fileList[b_os].getPath();
promptError(fileName + " could not be read");
e.printStackTrace();
System.exit(1);
}
dx = w / 2;
dy = h / 2;
}

public void promptError(String msg) {
JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.ERROR_MESSAGE);
}

public void keyTyped(KeyEvent e) {
}