Hi!
I have started to read the java 2D games tutorial, and I don’t understand a thing , following i post the code :
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class Board extends JPanel{
Image Cattura;
public Board(){
ImageIcon img= new ImageIcon("Cattura.jpg");
Cattura= img.getImage();
}
public void paint(Graphics g){
Graphics2D g2d= (Graphics2D) g;
g2d.drawImage(Cattura,10,10,null);
}
}
This is the panel file ;
import javax.swing.JFrame;
public class Image extends JFrame {
public Image() {
add(new Board());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(280, 240);
setLocationRelativeTo(null);
setTitle("Cattura");
setVisible(true);
}
public static void main(String[] args) {
new Image();
}
}
And this is the main , I don’t understand how is possible the drawing of image, yes there is the drawing method “paint” but this is not recall in the main so what it the logic of this trick???