atm959

Component.java

Mar 15th, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. package com.atm959.sourceCode;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics2D;
  7. import java.awt.Image;
  8. import java.io.File;
  9. import java.io.IOException;
  10. import java.util.Random;
  11.  
  12. import javax.swing.JFrame;
  13.  
  14. public class Component extends Applet implements Runnable {
  15.    
  16.     private static final long serialVersionUID = 1L;
  17.    
  18.     public static String TITLE = "Image Displayer...?";
  19.     public static Dimension SIZE = new Dimension(700, 560);
  20.     public static Dimension PIXELSIZE = new Dimension(4, 4);
  21.     public static Dimension PIXEL = new Dimension(SIZE.width / PIXELSIZE.width, SIZE.height / PIXELSIZE.height);
  22.     public static double sX = 0, sY = 0;
  23.     public static boolean isRunning = false;
  24.     private Image screen;
  25.     public static Random random = new Random();
  26.     File dialogsOne = new File("dialogs/dialogsOne.txt");
  27.    
  28.     public Component(){
  29.        
  30.         setPreferredSize(SIZE);
  31.        
  32.     }
  33.    
  34.     public void start(){
  35.        
  36.         isRunning = true;
  37.         new Thread(this).start();
  38.        
  39.     }
  40.    
  41.     public void stop(){
  42.        
  43.         isRunning = false;
  44.        
  45.     }
  46.    
  47.     public static void main(String args[]){
  48.        
  49.         Component component = new Component();
  50.        
  51.         JFrame frame = new JFrame();
  52.         frame.add(component);
  53.         frame.pack();
  54.         frame.setTitle(TITLE);
  55.         frame.setResizable(false);
  56.         frame.setLocationRelativeTo(null);
  57.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  58.         frame.setVisible(true);
  59.        
  60.         component.start();
  61.        
  62.     }
  63.    
  64.     public void tick(){
  65.        
  66.        
  67.        
  68.     }
  69.    
  70.     public void render() throws IOException{
  71.        
  72.         Graphics2D g = (Graphics2D)screen.getGraphics();
  73.        
  74.         g.drawLine(0, 0, PIXEL.width, PIXEL.height);
  75.        
  76.         g = (Graphics2D)getGraphics();
  77.         g.drawImage(screen, 0, 0, SIZE.width + 10, SIZE.height + 10, 0, 0, PIXEL.width, PIXEL.height, null);
  78.         g.dispose();
  79.        
  80.     }
  81.    
  82.     public void run() {
  83.        
  84.         screen = createVolatileImage(PIXEL.width, PIXEL.height);
  85.        
  86.         while(isRunning){
  87.            
  88.             try{
  89.                
  90.                 tick();
  91.                 render();
  92.                 Thread.sleep(5);
  93.                
  94.             } catch(Exception e){
  95.                
  96.                 e.printStackTrace();
  97.                
  98.             }
  99.            
  100.         }
  101.        
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment