package net.kc7.activityframe;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JPanel;
import javax.swing.Timer;

public abstract class Activity extends JPanel implements ActionListener {

	private static final long serialVersionUID = 1L;
	
	private final int ACTIVITY_FRAMERATE;
	
	protected boolean active = false;
	protected Timer timer;
	
	protected static final int UP = KeyEvent.VK_UP;
	protected static final int DOWN = KeyEvent.VK_DOWN;
	protected static final int LEFT = KeyEvent.VK_LEFT;
	protected static final int RIGHT = KeyEvent.VK_RIGHT;
	
	public Activity(int width, int height, int framerate) {	
		ACTIVITY_FRAMERATE = framerate;
		
		setFocusable(true);
		setPreferredSize(new Dimension(width, height));
		addKeyListener(new KeyHandler());
		
		loadResources();
		startActivity();	
	}
	
	// Loads images, audio, and other assets
	protected abstract void loadResources();
	
	// Kicks off the activity
	protected void startActivity() {
		active = true;
		timer = new Timer(ACTIVITY_FRAMERATE, this);
		timer.start();
	}
	
	// Handle data and execute tasks every frame
	protected abstract void processInfo();
	
	// Draws the View every active frame
	protected abstract void drawView(Graphics g);
	
	// Draws the Void for an inactive frame
	protected abstract void drawVoid(Graphics g);
	
	// Handles key values
	protected abstract void handleKey(int key);
	
	@Override
	public final void actionPerformed(ActionEvent e) {
		if (active) processInfo();
		repaint();
	}
	
	@Override
	protected final void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		if (active) drawView(g);
		else drawVoid(g);
	}
	
	private final class KeyHandler extends KeyAdapter {
		
		@Override
		public void keyPressed(KeyEvent e) {
			handleKey(e.getKeyCode());
		}
	}
}

@@ -291,25 +291,16 @@
 %0Apublic 
-abstract 
 class Ac
@@ -402,24 +402,97 @@
 D = 1L;%0D%0A%09%0D%0A
+%09private final int ACTIVITY_WIDTH;%0D%0A%09private final int ACTIVITY_HEIGHT;%0D%0A
 %09private fin
@@ -525,23 +525,21 @@
 %0D%0A%09%0D%0A%09pr
-otec
+iva
 te
-d
  boolean
@@ -560,33 +560,8 @@
 e;%0D%0A
-%09protected Timer timer;%0D%0A
 %09%0D%0A%09
@@ -835,16 +835,72 @@
 te) %7B%09%0D%0A
+%09%09ACTIVITY_WIDTH = width;%0D%0A%09%09ACTIVITY_HEIGHT = height;%0D%0A
 %09%09ACTIVI
@@ -990,21 +990,39 @@
 ion(
-width, height
+ACTIVITY_WIDTH, ACTIVITY_HEIGHT
 ));%0D
@@ -1114,16 +1114,28 @@
 %0D%0A%09%0D%0A%09//
+ OVERRIDE --
  Loads i
@@ -1177,29 +1177,23 @@
 otected 
-abstract void
+boolean
  loadRes
@@ -1200,25 +1200,57 @@
 ources()
-;%0D%0A%09%0D%0A%09//
+ %7B%0D%0A%09%09return true;%0D%0A%09%7D%0D%0A%09%0D%0A%09// DEFAULT --
  Kicks o
@@ -1277,20 +1277,23 @@
 otected 
-void
+boolean
  startAc
@@ -1320,24 +1320,30 @@
  = true;%0D%0A%09%09
+Timer 
 timer = new 
@@ -1395,25 +1395,57 @@
 rt();%0D%0A%09
-%7D%0D%0A%09%0D%0A%09//
+%09%0D%0A%09%09return true;%0D%0A%09%7D%0D%0A%09%0D%0A%09// OVERRIDE --
  Handle 
@@ -1487,300 +1487,57 @@
 %0A%09pr
-otected abstract void processInfo();%0D%0A%09%0D%0A%09// Draws the View every active frame%0D%0A%09protected abstract void drawView(Graphics g);%0D%0A%09%0D%0A%09// Draws the Void for an inactive frame%0D%0A%09protected abstract void drawVoid(Graphics g);%0D%0A%09%0D%0A%09// Handles key values%0D%0A%09protected abstract void handleKey(int key);
+ivate boolean processInfo() %7B%0D%0A%09%09return true;%0D%0A%09%7D
 %0D%0A%09%0D
@@ -1667,24 +1667,21 @@
 ride%0D%0A%09p
-rotected
+ublic
  final v
@@ -1798,24 +1798,269 @@
 g);%0D%0A%09%7D%0D%0A%09%0D%0A
+%09// OVERRIDE -- Draws the View every active frame%0D%0A%09protected boolean drawView(Graphics g) %7B%0D%0A%09%09return true;%0D%0A%09%7D%0D%0A%09%0D%0A%09protected boolean drawVoid(Graphics g) %7B%0D%0A%09%09return true;%0D%0A%09%7D%0D%0A%09%0D%0A%09private boolean handleKey(int key) %7B%0D%0A%09%09return true;%0D%0A%09%7D%0D%0A%09%0D%0A
 %09private fin
@@ -2158,16 +2158,21 @@
 t e) %7B%0D%0A
+%09%09%09%0D%0A
 %09%09%09handl
@@ -2194,16 +2194,21 @@
 de());%0D%0A
+%09%09%09%0D%0A
 %09%09%7D%0D%0A%09%7D%0D

Revert "Major Update -- v0.9"