FPS Counter added to title

main
sigonasr2, Sig, Sigo 3 years ago committed by GitHub
parent 3c027104e9
commit b203727aae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/sig/Panel.java
  2. 6
      src/sig/PolygonFill.java

@ -9,13 +9,16 @@ import java.awt.image.MemoryImageSource;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Panel extends JPanel implements Runnable {
JFrame window;
public int pixel[];
public int width=1280;
public int height=720;
final int CIRCLE_PRECISION=32;
final int OUTLINE_COL=Color.BRIGHT_WHITE.getColor();
private Thread thread;
private Image imageBuffer;
private MemoryImageSource mImageProducer;
@ -25,9 +28,12 @@ public class Panel extends JPanel implements Runnable {
double x_offset=0;
double y_offset=0;
int frameCount=0;
long lastSecond=0;
int lastFrameCount=0;
public Panel() {
public Panel(JFrame f) {
super(true);
this.window=f;
thread = new Thread(this, "MyPanel Thread");
}
@ -69,6 +75,14 @@ public class Panel extends JPanel implements Runnable {
mImageProducer.newPixels();
// draw it on panel
g.drawImage(this.imageBuffer, 0, 0, this);
if (window!=null&&System.currentTimeMillis()-lastSecond>=1000) {
window.setTitle(PolygonFill.PROGRAM_NAME+" - FPS: "+(frameCount-lastFrameCount));
lastFrameCount=frameCount;
lastSecond=System.currentTimeMillis();
}
frameCount++;
}
/**

@ -3,9 +3,10 @@ package sig;
import javax.swing.JFrame;
public class PolygonFill {
public static final String PROGRAM_NAME="Polygon Fill Renderer";
public static void main(String[] args) {
Panel p = new Panel();
JFrame f = new JFrame("Polygon Fill Renderer");
JFrame f = new JFrame(PROGRAM_NAME);
Panel p = new Panel(f);
p.init();
@ -14,7 +15,6 @@ public class PolygonFill {
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
int i=0;
p.render();
}
}

Loading…
Cancel
Save