Reputation: 141
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
Upvotes: 0
Views: 101
Reputation: 109823
don't to use Thread.sleep(1000);, this code line lock Event Dispatch Thread,
no idea for why reason you need to pause code execution for one second, use Swing Timer instead
for showing the Image in Java to use
don't paint XxxImage
or Icon / ImageIcon
directly to the JFrame
, use JPanel / JComponent
or JLabel
Upvotes: 3