Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package vaysym;
- import java.awt.Canvas;
- import javax.swing.JFrame;
- public class Launcher extends Canvas implements Runnable{
- public static JFrame frame;
- private Thread thread;
- private boolean running = false;
- public static String inputString = "";
- public Launcher(){
- new Window(this);
- this.addKeyListener(new Keyboard());
- this.start();
- }
- public void setFrame(JFrame frame){
- Launcher.frame = frame;
- }
- public synchronized void start(){
- thread = new Thread(this);
- thread.start();
- running = true;
- }
- public synchronized void stop(){
- try{
- thread.join();
- running = false;
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- public void run(){
- long lastTime = System.nanoTime();
- double amountOfTicks = 60;
- double ns = 1000000000 / amountOfTicks;
- double delta = 0;
- long timer = System.currentTimeMillis();
- while(running){
- long now = System.nanoTime();
- delta += (now-lastTime)/ns;
- lastTime = now;
- while(delta >= 1){
- delta--;
- }
- if(System.currentTimeMillis()-timer > 1000){
- timer += 1000;
- }
- }
- }
- public static void main(String args[]){
- new Launcher();
- }
- }
Add Comment
Please, Sign In to add comment