Advertisement
Guest User

Untitled

a guest
Nov 6th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package com.c0decub.gtest;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.event.MouseEvent;
  9. import java.awt.event.MouseListener;
  10. import java.awt.image.BufferStrategy;
  11. import java.awt.image.BufferedImage;
  12. import java.awt.image.DataBufferInt;
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.io.InputStream;
  16.  
  17. import javax.imageio.ImageIO;
  18. import javax.swing.*;
  19.  
  20. public class graphicsTest extends Canvas implements Runnable {
  21.    
  22.     public static final int GAME_WIDTH = 320;
  23.     public static final int GAME_HEIGHT = 240;
  24.     public static final int SCALE = 2;
  25.     public static final int SCALE_IMG = 3;
  26.    
  27.     private Thread thread;
  28.     private boolean running;
  29.    
  30.     public Graphics g;
  31.    
  32.     private static BufferedImage blood = Images.load("blood.png");
  33.    
  34.     public static void main(String[] args) {
  35.         graphicsTest gObj = new graphicsTest();
  36.        
  37.         JFrame frame = new JFrame("graphics");
  38.         frame.add(gObj);
  39.         frame.pack();
  40.         frame.setResizable(false);
  41.         frame.setLocationRelativeTo(null);
  42.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  43.         frame.setVisible(true);
  44.        
  45.         gObj.start();
  46.     }
  47.    
  48.     public synchronized void start() {
  49.         thread = new Thread(this);
  50.        
  51.         running = true;
  52.        
  53.         thread.start();
  54.     }
  55.    
  56.     public synchronized void stop(){
  57.         running = false;
  58.     }
  59.  
  60.     public graphicsTest(){
  61.         int w = GAME_WIDTH * SCALE;
  62.         int h = GAME_HEIGHT * SCALE;
  63.         setPreferredSize(new Dimension(w, h));
  64.         setMaximumSize(new Dimension(w, h));
  65.         setMinimumSize(new Dimension(w, h));
  66.        // setBackground(Color.BLACK);
  67.     }
  68.  
  69.     public void run() {
  70.         while (running){
  71.             render();
  72.         }
  73.     }
  74.    
  75.     public void render(){
  76.         Images.load("blood.png");
  77.         g.drawImage(blood, 0, 0, this);
  78.     }
  79.    
  80.    
  81. }
  82.  
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement