package com.ai.snake;
import javax.swing.*;
public class StartGame {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setBounds(10,10,900,720);
frame.setResizable(false);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(new GamePanel());
frame.setVisible(true);
}
}
package com.ai.snake;
import javax.swing.*;
import java.awt.*;
public class GamePanel extends JPanel {
@Override
protected void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.WHITE);
Data.header.paintIcon(this,g,15,5);
g.fillRect(15,60,850,600);
}
}
package com.ai.snake;
import javax.swing.*;
import java.net.URL;
public class Data {
private static URL headerURL = Data.class.getResource("statics/header.jpg");
public static ImageIcon header = new ImageIcon(headerURL);
public static URL upURL = Data.class.getResource("statics/up.jpg");
public static URL downURL = Data.class.getResource("statics/down.jpg");
public static URL leftURL = Data.class.getResource("statics/left.jpg");
public static URL rightURL = Data.class.getResource("statics/right.jpg");
public static ImageIcon up = new ImageIcon(upURL);
public static ImageIcon down = new ImageIcon(downURL);
public static ImageIcon left = new ImageIcon(leftURL);
public static ImageIcon right = new ImageIcon(rightURL);
public static URL bodyURL = Data.class.getResource("statics/body.jpg");
public static ImageIcon body = new ImageIcon(bodyURL);
public static URL foodURL = Data.class.getResource("statics/food.jpg");
public static ImageIcon food = new ImageIcon(foodURL);
}