Friday, 13 September 2013

Java Eclipse Programming Need Support

Java Eclipse Programming Need Support

I am having problems with my programming (Im a novice) of this java class
file it does go with other class files. I would appreciate it if someone
can help with this. I'm getting stressed over trying to figure out my
problem.
this is what i was trying to learn it off of
Part 1: http://www.youtube.com/watch?v=x4QaOmDV9eE
Part 2: http://www.youtube.com/watch?v=x4QaOmDV9eE
Part 3: http://www.youtube.com/watch?v=TY9bDWuAaVg
If You want the file it is: http://www.mediafire.com/?s1mmlrr9arfrwis
I'm having problems with these in the class
* public class GameCanvas extends Canvas implements Runnable{
* long beginTime = System.currentTimeMillis();
* t.sleep(sleepTime);



Here is my code:
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
public class GameCanvas extends Canvas implements Runnable{
int FWidth = 800;
int FHeight = 600;
public long period = 10;
public BufferStrategy Buffer;
public Graphics graphics;
private Thread t;
public GameCanvas(){
this.setIgnoreRepaint(true);
this.setBounds (0, 0, FWidth, FHeight);
this.setBackground(Color.white);
this.setVisible(true);
}
public void addNotify(){
super.addNotify();
this.createBufferStrategy(2);
this.Buffer = this.getBufferStrategy();
startGame();
}
public void startGame(){
if(t == null){
t = new Thread(this);
t.start();
}
}
public void run(){
while(true){
long beginTime = System.currentTimeMillis();
Update();
Render();
Draw();
long timeTaken = System.currentTimeMillis();
long sleepTime = period - timeTaken;
try{
t.sleep(sleepTime);
}
catch(Exception e) {
}
}
}
public void Update(){
}
public void Render(){
graphics = Buffer.getDrawGraphics();
graphics.setColor(Color.white);
graphics.fillRect(0, 0, FWidth, FHeight);
//Paint :D
}
public void Draw(){
if(!Buffer.contentsLost()){
Buffer.show();
if(graphics != null){
graphics.dispose();
}
}
}
}

No comments:

Post a Comment