Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Something
Tuesday, June 3rd, 2008 at 8:30:34am UTC 

  1. package stein;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.GraphicsConfiguration;
  6. import java.awt.GraphicsDevice;
  7. import java.awt.GraphicsEnvironment;
  8. import java.awt.image.BufferStrategy;
  9. import java.text.Format;
  10. import java.util.Formatter;
  11.  
  12. import javax.swing.JFrame;
  13.  
  14. /**
  15. * First try at gfx test.
  16. *
  17. * @author stein
  18. *
  19. */
  20. public class TestOne {
  21.  
  22.         GraphicsEnvironment gfxEnv;
  23.         GraphicsDevice gfxDev;
  24.         GraphicsConfiguration gfxConf;
  25.  
  26.         JFrame frame;
  27.  
  28.         public void go() {
  29.                 gfxEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
  30.                 gfxDev = gfxEnv.getDefaultScreenDevice();
  31.                 gfxConf = gfxDev.getDefaultConfiguration();
  32.  
  33.                 frame = new JFrame(gfxConf);
  34.                 // frame.setUndecorated(true);
  35.                 frame.setIgnoreRepaint(true);
  36.                 frame.setSize(300, 200);
  37.                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  38.  
  39.                 frame.setVisible(true);
  40.                 // gfxDev.setFullScreenWindow(frame); FIXME on or off, as needed ...
  41.  
  42.                 frame.createBufferStrategy(2);
  43.                 BufferStrategy bs = frame.getBufferStrategy();
  44.  
  45.                 boolean done = false;
  46.                 int frames = 0;
  47.                 long lastTime = System.currentTimeMillis();
  48.                 String fpsString = "FPS: ???";
  49.  
  50.                 while (!done) {
  51.                         // render loop
  52.                         Graphics g = bs.getDrawGraphics();
  53.                         try {
  54.                                 renderPicture(g);
  55.                                 g.drawString(fpsString, 10, 40);
  56.  
  57.                                 long thisTime = System.currentTimeMillis();
  58.                                 if (thisTime - lastTime >= 500)
  59.                                 {
  60.                                         Formatter f = new Formatter();
  61.                                         double fps = (frames * 1000.0) / (thisTime - lastTime);
  62.                                         lastTime = thisTime;
  63.                                         frames=0;
  64.                                         f.format("FPS: %6.1f", fps);
  65.                                         fpsString=f.toString();
  66.                                         //System.out.println("fsp is "+fps+"|"+f.toString());
  67.                                 }
  68.  
  69.                         } finally {
  70.                                 g.dispose();
  71.                                 frames++;
  72.                         }
  73.                         g.dispose();
  74.                         bs.show();
  75. //                  try {
  76. //                        Thread.sleep(20);
  77. //                  } catch (InterruptedException e) {
  78. //                  }
  79.  
  80.                 }
  81.  
  82.                 frame.setVisible(false);
  83.                 frame.dispose();
  84.  
  85.         }
  86.         double T = System.currentTimeMillis();
  87.  
  88.         void renderPicture(Graphics g) {
  89.                 // draw something
  90.                
  91.                 double t = System.currentTimeMillis();
  92.                 double arc = t/1000.0/10.0;
  93.                
  94.                 arc = arc-Math.floor(arc);
  95.                 System.out.printf("arc : %5.3f, %5.1f deg\n",arc,arc*360);
  96.                
  97.                 double minute = (long)((t-T) / 1000.0 / 60.0);
  98.                 long seconds = (long)((t-T) / 1000.0);
  99.                 System.out.println("MS: "+minute+":"+seconds);
  100.                
  101.                 g.setColor(Color.WHITE);
  102.                 g.fillRect(0, 0, frame.getWidth(), frame.getHeight());
  103.                 g.setColor(Color.BLACK);
  104.                 g.drawArc(100, 80, 100, 100, (int)(360*arc), 10);
  105.         }
  106.  
  107.         public static void main(String[] args) {
  108.                 // TODO Auto-generated method stub
  109.  
  110.                 new TestOne().go();
  111.  
  112.         }
  113.  
  114. }

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right