question: public static boolean createJPEG ( Window window , String fileName ) { BufferedImage bi = null ; if ( window == null || fileName == null ) new IllegalArgumentException ( "ScreenShot.createJPEG Window os NULL" ) ; File file = getJPGFile ( window ) ; if ( file == null ) return false ; log . config ( "File=" + file ) ; if ( file . exists ( ) ) file . delete ( ) ; Iterator writers = ImageIO . getImageWritersByFormatName ( "jpg" ) ; ImageWriter writer = ( ImageWriter ) writers . next ( ) ; if ( writer == null ) { log . log ( Level . SEVERE , "no ImageWriter" ) ; return false ; } try { Thread . sleep ( 1000 ) ; bi = getImage ( window ) ; } catch ( InterruptedException ex ) { log . log ( Level . SEVERE , "ex" , ex ) ; } try { ImageOutputStream ios = ImageIO . createImageOutputStream ( file ) ; writer . setOutput ( ios ) ; writer . write ( bi ) ; ios . flush ( ) ; ios . close ( ) ; } catch ( IOException ex ) { log . log ( Level . SEVERE , "ex" , ex ) ; return false ; } return true ; }
target:  Create JPEG file from window