Jumat, 01 September 2023

Game Java Dua

 



Run.java

package core;

/**
 *
 * @author Acer
 */
public class Run {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        new Window("Game Kotak").start();
        
    }
    
}


Window.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package core;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/**
 *
 * @author Acer
 */
public class Window extends Canvas implements Runnable{
    private static final long serialVersionUID=1L;
    private Thread thread;
    private boolean running=false;
    public Window(String Title){
    JFrame frame=new JFrame(Title);
    frame.setSize(800,600);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(true);
    frame.setVisible(true);
    frame.add(this);
}
    public void start(){
        running=true;
        thread=new Thread(this);
        thread.start();
    }
    public void stop(){
        running=false;
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
    }
public void run(){
        while(running){
        tick();
        Render();
    }
    
}
public void tick(){
    
}
public void Render(){
    BufferStrategy bs=this.getBufferStrategy();
    if(bs==null){
        this.createBufferStrategy(2);
        bs=this.getBufferStrategy();
    }
    Graphics g=bs.getDrawGraphics();
    g.setColor(Color.white);
    g.fillRect(0,0,this.getWidth(), this.getHeight());
    bs.show();
    g.dispose();
}
}




Tidak ada komentar: