From af24e3a1a8dc982f71a2dbb8aa00521f64138026 Mon Sep 17 00:00:00 2001 From: 17bthompson Date: Thu, 26 May 2016 09:15:42 -0400 Subject: [PATCH] Added JPanel instantiation and Timers --- src/tanks/Tanks.java | 63 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/src/tanks/Tanks.java b/src/tanks/Tanks.java index ae817f5..4eb6e70 100644 --- a/src/tanks/Tanks.java +++ b/src/tanks/Tanks.java @@ -7,10 +7,14 @@ package tanks; +import java.awt.Graphics; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.util.ArrayList; import javax.swing.JFrame; import javax.swing.JPanel; +import javax.swing.Timer; public class Tanks { @@ -22,22 +26,58 @@ public class Tanks private ArrayList bullets; private Player p; private ArrayList enemy; + Timer move; //constructor public Tanks() { System.out.println("Mrs. Shaw test"); + panel = new JPanel() + { + protected void paintComponent(Graphics g) + { + //Paint Wave + //wave.draw(g); + for(Bullet b: bullets) + { + b.draw(g); + } + + for(Enemy en: enemy) + { + en.draw(g); + } + + p.draw(g); + } + }; + frame.add(panel); + frame.setVisible(true); + + //Timer + ActionListener tic = new ActionListener() + { + //Override + public void actionPerformed(ActionEvent e) + { + p.move(); + for(Bullet b: bullets) + { + b.move(); + } + + for(Enemy en: enemy) + { + en.move(); + } + panel.repaint(); + } + }; + + move = new Timer(30, tic); //Timer that moves things... Moves the player and enemies? + move.start(); } - //creates a new instance of tanks to run - public static void main(String[] arguments) - { - Tanks runnable = new Tanks(); - } - - - - /* @@ -227,6 +267,11 @@ public class Tanks */ private class Tank extends Enemy { + + @Override + public void move() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } }