Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.atm959.sourceCode;
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.io.File;
- import java.io.IOException;
- import java.util.Random;
- import javax.swing.JFrame;
- public class Component extends Applet implements Runnable {
- private static final long serialVersionUID = 1L;
- public static String TITLE = "Image Displayer...?";
- public static Dimension SIZE = new Dimension(700, 560);
- public static Dimension PIXELSIZE = new Dimension(4, 4);
- public static Dimension PIXEL = new Dimension(SIZE.width / PIXELSIZE.width, SIZE.height / PIXELSIZE.height);
- public static double sX = 0, sY = 0;
- public static boolean isRunning = false;
- private Image screen;
- public static Random random = new Random();
- File dialogsOne = new File("dialogs/dialogsOne.txt");
- public Component(){
- setPreferredSize(SIZE);
- }
- public void start(){
- isRunning = true;
- new Thread(this).start();
- }
- public void stop(){
- isRunning = false;
- }
- public static void main(String args[]){
- Component component = new Component();
- JFrame frame = new JFrame();
- frame.add(component);
- frame.pack();
- frame.setTitle(TITLE);
- frame.setResizable(false);
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- component.start();
- }
- public void tick(){
- }
- public void render() throws IOException{
- Graphics2D g = (Graphics2D)screen.getGraphics();
- g.drawLine(0, 0, PIXEL.width, PIXEL.height);
- g = (Graphics2D)getGraphics();
- g.drawImage(screen, 0, 0, SIZE.width + 10, SIZE.height + 10, 0, 0, PIXEL.width, PIXEL.height, null);
- g.dispose();
- }
- public void run() {
- screen = createVolatileImage(PIXEL.width, PIXEL.height);
- while(isRunning){
- try{
- tick();
- render();
- Thread.sleep(5);
- } catch(Exception e){
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment