1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;

class TestDesktop extends JPanel implements Runnable
{
    BufferedImage buffer;
    Graphics2D g2d;
    Thread gameloop1;
    fpscounter FPS = new fpscounter();

    TestDesktop()
    {
        super();
        setFocusable(true);;
        setSize(1200,800);
        buffer = new BufferedImage(1200,800,BufferedImage.TYPE_INT_ARGB);
        g2d = buffer.createGraphics();
        setVisible(true);
        start();
    }

    public void start()
    {
        gameloop1 = new Thread(this);
        gameloop1.start();
    }

       public void run()
    {
        Thread t = Thread.currentThread();
        while (t == gameloop1)
        {


           System.out.println(""+FPS.getFPS());
            repaint();
        }
    }

       public void paintComponent(Graphics g)
       {
           g2d.setColor(Color.BLACK);
           g2d.fillRect(0,0,1200,800);
           g2d.setColor(Color.WHITE);
           g2d.drawString("FPS: "+FPS.getFPS(),20, 30);
           g.drawImage(buffer,0,0,this);
           FPS.tick();
       }


       public static void main(String[] args)
       {
           TestDesktop p = new TestDesktop();
            JFrame holder = new JFrame("Prototype");
            holder.add(p);
            holder.setVisible(true);
            holder.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            holder.setSize(1200,800);
       }
}