Reputation: 617
This is all I have so far. I have read the oracle documentation on drawing and creating images, But I still cant figure it out.
final BufferedImage image = ImageIO.read(new File("BeachRoad_double_size.png"));
final JPanel pane = new JPanel();
frame.add(pane);
int delay = 1000; //milliseconds
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Graphics gg = image.getGraphics();
System.out.println("sdfs");
pane.paintComponents(gg);
//g.drawImage(image, 0, 0, null);
}
};
new Timer(delay, taskPerformer).start();
Upvotes: 0
Views: 1042
Reputation: 347204
paintComponent
directly, in fact, you should never have a need to call paint
directlyInstead. Create a custom component, say from something like JPanel
, override it's paintComponent
method and perform all you custom painting there...
public class ImagePane extends JPanel {
private BufferedImage bg;
public ImagePane(BufferedImage bg) {
this.bg = bg;
}
public Dimension getPreferredSize() {
return bg = null ? new Dimension(200, 200) : new Dimension(bg.getWidth(), bg.getHeight());
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (bg != null) {
g.drawImage(bg, 0, 0, this);
}
}
}
Take a look at
For more details
Upvotes: 3