// Define an image
final int width = 256;
final int height = 256;
final int[] pixels = new int[ width * height ];
final ARGBScreenImage simg = new ARGBScreenImage( width, height, pixels );
// Paint a yellow rectangle
final Graphics g = simg.image().getGraphics();
g.setColor( Color.yellow );
g.fillRect( 0, 0, 100, 100 );
g.dispose();
final BufferedImage[] capture = new BufferedImage[ 1 ];
final JFrame[] frame = new JFrame[ 2 ];
// Show the image in a JFrame
SwingUtilities.invokeAndWait( new Runnable()
{
@Override
public void run()
{
frame[ 0 ] = frame( simg.image(), "Test ARGBScreenImage" );
frame[ 0 ].setVisible( true );
}
} );
// Wait for all sorts of asynchronous events
Thread.sleep( 2000 );
SwingUtilities.invokeAndWait( new Runnable()
{
@Override
public void run()
{
// Paint into the image again
final Graphics g2 = simg.image().getGraphics();
g2.setColor( Color.red );
g2.fillRect( 100, 100, 100, 100 );
g2.dispose();
final JPanel panel = ( JPanel ) frame[ 0 ].getContentPane().getComponent( 0 );
panel.invalidate();