Hi Guys
Just starting to make my first java game, im getting a few errors.
Im just trying to figure a few things about about the game loops before i get started and this is driving me crazy
when i just call the renderer to repaint after i initialize the jframe, it works...
but once i put it in a loop.... (note this is not going to be my loop, i was just trying somthing out...)
I get errors
run:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Any input would be greatly appreciated. I dont understand what is null and why it is null only in a loop
see my main class and renderer class below
//my main game classs
package ballgame;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.JFrame;
/**
*
* @author jonathan
*/
public class BallGame {
private int HIEGHT;
private int WIDTH;
private int paddleHieght;
private int paddleWidth;
public Renderer Renderer;
public static BallGame ballGame;
boolean running = true;
public Rectangle Paddle;
int y = 0;
public BallGame() {
Dimensions();
Renderer = new Renderer();
JFrame jframe = new JFrame("Ball Game");
jframe.setResizable(false);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setSize(WIDTH, HIEGHT);
jframe.add(Renderer);
jframe.setVisible(true);
run();
// Renderer.repaint();
}
final void run(){
while (running){
Renderer.repaint();
}
}
void paintPaddle(Graphics g) {
g.setColor(Color.black);
g.fillRect(Paddle.x,Paddle.y,Paddle.width,Paddle.height);
}
void Repaint(Graphics g) {
g.setColor(Color.CYAN);
g.fillRect(0, 0, WIDTH, HIEGHT);
paintPaddle(g);
}
void update(long Elapsed) {
}
final void Dimensions() {
//here i am getting the users screen size.....
//this is what everything will be based on....
WIDTH = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width;
HIEGHT = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height;
paddleHieght = HIEGHT / 15;
paddleWidth = WIDTH / 7;
Paddle = new Rectangle(WIDTH / 2 - (paddleWidth / 2),HIEGHT - paddleHieght,paddleWidth, paddleHieght);
}
public static void main(String[] args) {
ballGame = new BallGame();
}
}
//my renderer class
package ballgame;
import java.awt.Graphics;
import javax.swing.JPanel;
/**
*
* @author jonathan
*/
public class Renderer extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g); //To change body of generated methods, choose Tools | Templates.
BallGame.ballGame.Repaint(g);
}
}