Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:42:19+00:00 2026-06-01T09:42:19+00:00

// Here’s my code: Main Class: import java.awt.*; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.awt.image.BufferStrategy;

  • 0

// Here’s my code:

Main Class:

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
public class Display extends Canvas implements Runnable{
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension dim = toolkit.getScreenSize();
    public static int WIDTH;
    public static int HEIGHT;
    public static final String title = "First Person Game";
    public static Thread thread;
    public static Screen screen;
    public static  BufferedImage img;
    public static boolean running = false;
    public static int[] pixels;
    public static Render render;
    public Display(){
        WIDTH = dim.width;
        HEIGHT = dim.height;
        screen = new Screen(WIDTH, HEIGHT);
        img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
        pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
    }
    private void start(){
        if(running){
            return;
        }else{
            running = true;
            thread = new Thread(this);
            thread.start();
        }
    }
    private void stop(){
        if(!running){
            return;
        }else{
            running = false;
            try{
                thread.join();
            }catch(Exception x){
                System.exit(0);
            }
        }
    }
    public void run(){
        while(running){
            render();
        }
    }
    public void render(){
        BufferStrategy bs = this.getBufferStrategy();
        if(bs == null){
            createBufferStrategy(3);
            return;
        }
        screen.render();
        for(int i = 0; i < WIDTH * HEIGHT; i++){
            pixels[i] = screen.pixels[i];
        }
        Graphics g = bs.getDrawGraphics();
        g.drawImage(img, 0, 0, WIDTH, HEIGHT, null);
        g.dispose();
        bs.show();
    }
    public static void main(String args[]){
        JFrame frame = new JFrame();
        BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
        Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
        frame.getContentPane().setCursor(blankCursor);
        Display game = new Display();
        frame.setUndecorated(true);
        frame.add(game);
        frame.setTitle(title);
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(WIDTH, HEIGHT);
        frame.setLocationRelativeTo(null);
        frame.setResizable(false);
        frame.setVisible(true);
        fps f = new fps();
        game.start();
    }
}



The class I need to call:

public class fps{
    public void fps(){
        System.out.println("Test 1 successful.");
        int frames = 0;
        double unprocessedSeconds = 0;
        long previousTime = System.nanoTime();
        double secondsPerTick = 1 / 60.0;
        int tickCount = 0;
        boolean ticked = false;
        Display c = new Display();
        System.out.println("Test 2 successful.");
        c.render();
        long currentTime = System.nanoTime();
        long passedTime = currentTime - previousTime;
        previousTime = currentTime;
        unprocessedSeconds += passedTime / 1000000000.0;
        while(unprocessedSeconds > secondsPerTick){
            System.out.println("Test 3 successful.");
            tick();
            unprocessedSeconds -= secondsPerTick;
            ticked = true;
            tickCount++;
            if(tickCount % 60 == 0){
                System.out.println(frames + " fps");
                previousTime += 1000;
                frames = 0;
            }
        }
        if(ticked){
            c.render();
            frames++;
        }
        c.render();
        frames++;
    }
    public void tick(){}
}

/* I don’t know how to do this, I’ve been trying all sorts of things. I basically need *to make sure fps is printing into the console while display is running. I can’t seem to so */ this. I tried in method run() but it just wouldn’t call it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:42:20+00:00Added an answer on June 1, 2026 at 9:42 am

    I beleive you need to create an instance of the fps class in your main class, and then call the method through it.

    fps nameOfClassInstance = new fps(//don't forget anything you need to send for constructor);
    fps.run();
    

    At least this is how it is in C# which I know is very similar to java.

    if this doesn’t help,then I beleive it is a threading issue, and you need to make sure you are handling the threads properly. ( I can’t help with this issue, I am still green to java threading.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the stacktrace: 04-10 18:09:36.393: E/AndroidRuntime(26592): FATAL EXCEPTION: main 04-10 18:09:36.393: E/AndroidRuntime(26592): java.lang.RuntimeException:
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:
Here's a Clone() implementation for my class: MyClass^ Clone(){ return gcnew MyClass(this->member1, this->member2); }
Here's my scenario: <!-- Normal Control --> <div class=required> <label for=address1>Address line 1</label> <input
Here is my persistence.xml : <?xml version=1.0 encoding=UTF-8?> <persistence xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd version=1.0>
Here is an example: I write html code inside of textarea, then I swap
Here is my code, which takes two version identifiers in the form 1, 5,
Here is my code...I have two dimensional matrices A,B. I want to develop the
Here is my code sample, let me know if it can be further improved?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.