0

I am not able to dynamically repaint() inside the Jframe.

public static BufferedImage createBufferedImage(BufferedImage image) 
{
    ColorModel cm = image.getColorModel();
    boolean premultiplied = cm.isAlphaPremultiplied();
    WritableRaster raster = image.copyData(image.getRaster());
    return new BufferedImage(cm, raster, premultiplied, null);
}


public static void main(String[] args) {


BufferedImage img = new BufferedImage(old_width_i, old_height_i, BufferedImage.TYPE_INT_RGB);

img=createBufferedImage(img_white_screen);



JFrame frame=new JFrame();
JLabel label = new JLabel(new ImageIcon(img));
frame.getContentPane().add(label, BorderLayout.WEST);
frame.pack();
frame.setVisible(true); 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


try {
    Thread.sleep(1000);
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

img.flush();
img=createBufferedImage(img_black_screen);
//  frame.removeAll();
//  frame.revalidate();
//  label.removeAll();
//  label = new JLabel(new ImageIcon(img));
//  frame.getContentPane().add(label, BorderLayout.WEST);

frame.repaint();
}

It basically, creates a screen with the first assignment to the "img" (i.e. img_white_screen) variable and does not change to the second assignment i.e. img_black_screen

JS_VIPER
  • 141
  • 1
  • 2
  • 7

1 Answers1

3
Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • I will be trying the posted answers, but the reason why I was using Sleep is to make the feeling of rotation... Say, the image was two circle having two different reference lines...I use, sleep so that user get a illusion of a wheel rotating.. any better solutions... NOTE:I am manually priting all the pixels values on the screen – JS_VIPER Feb 09 '13 at 19:31
  • @JS_VIPER for a [basic example](http://stackoverflow.com/questions/12593098/java-perform-action-every-x-seconds/12593132#12593132) – MadProgrammer Feb 09 '13 at 20:58