Hello Everyone,
My problem is that I don't understand why the paint method works, (display the string on the frame) although
it is not called in the Main method or in the constructor.
Please see the code below:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class JavaGame extends JFrame
{
public JavaGame()
{
setTitle("Java Game");
setSize(550,550);
setResizable(true);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint (Graphics g) // THIS METHOD SHOULD NOT RUN, without being called in the custructor
{
g.drawString("This is my first game", 75, 75);
g.drawLine(30, 30, 80, 80);
}
public static void main(String[] args)
{
new JavaGame();
}
}
Thank you in advance for your help!
Peter.
