Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import java.util.Date;
- public class Space extends JFrame{
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private boolean running=false;
- private long startZeit;
- private long endZeit;
- private Graphics g;
- private Image img;
- private int width;
- private int height;
- /**
- * erzeugt eine neue GameFrame, setzt sie visible und initialisiert alles
- */
- public Space(){
- gameFrame();
- this.setVisible(true);
- init();
- }
- /**
- * initialisiert Variablen, startet einen einen Loop
- */
- public void init(){
- running = true;
- loop();
- }
- /**
- * updatet alle "x" Millisekunden
- */
- public void loop(){
- while(running){
- startZeit = System.nanoTime();
- endZeit = startZeit;
- updateGame();
- paintToGame(g);
- while(((endZeit-startZeit)/1000000L)<40){
- endZeit = System.nanoTime();
- }
- }
- }
- /**
- * hier findet das Spielgeschehen statt
- */
- public void updateGame(){
- }
- /**
- * hier wird auf den GameFrame gezeichnet
- */
- public void paintToGame(Graphics g){
- g.drawImage (img, 0, 0, this);
- g.drawString("" + new Date(), width/2, height/2);
- }
- /**
- * erzeugt den GameFrame
- */
- public void gameFrame(){
- GraphicsEnvironment env = GraphicsEnvironment
- .getLocalGraphicsEnvironment();
- Rectangle bounds = env.getMaximumWindowBounds();
- width = bounds.width;
- height = bounds.height;
- setSize(width, height);
- setTitle("SpaceArc v1.0");
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- Container content= getContentPane();
- createBackground(g);
- }
- public void createBackground(Graphics g){
- if (img == null){
- try {
- img = ImageIO.read(new File("C:\\Users\\SuperStar\\Desktop\\Workspace\\SpaceArc\\Images\\Bg.jpg"));
- g = img.getGraphics();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- g.drawImage (img, 0, 0, this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement