Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help needed to change both set of images in programe when up/down button is pressed.

    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) {
    }

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,086
    Thanks
    38
    Thanked 498 Times in 492 Posts
    You might want to begin by understanding the difference between java and javascript code.
    You will probably get more responses on the correct forum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •