I don't quite understand why the graphics do not show up. I am new at Java and I am trying to do a tutorial of snake. At this stage, a black window with the title "Snake" should pop up, but what I get is an empty grey window instead.
Here is the code for my main class
import javax.swing.JFrame;
import java.awt.Color;
public class Main {
public static void main(String[] args){
JFrame obj = new JFrame();
Gameplay gameplay = new Gameplay();
obj.setBounds(10,10,905,700);
obj.setBackground(Color.DARK_GRAY);
obj.setResizable(false);
obj.setVisible(true);
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
obj.add(gameplay);
}
}
Here is the code for class Gameplay
import javax.swing.*;
import java.awt.*;
public class Gameplay extends JPanel {
public ImageIcon titleImage;
public Gameplay(){
}
public void paint(Graphics g)
{
// draw title image border
g.setColor(Color.white);
g.drawRect(24, 10, 851, 55);
//draw the title image
titleImage = new ImageIcon("snaketitle.jpg");
titleImage.paintIcon(this, g, 25, 11 );
//draw border for gameplay
g.setColor(Color.WHITE);
g.drawRect(24, 74, 851, 577);
// draw background for the gameplay
g.setColor(Color.black);
g.fillRect(25, 75, 850, 575);
}
}
Thanks for your help!