im making kind of like a shooting game where u have a rectangle on side of the screen and they shoot each other, im trying to make one fo the rectangles move up with the letter 'o' but it doesnt seem to be working, thanks.
import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.awt.image.ImageObserver; import java.io.*; import java.net.*; import java.applet.AudioClip; import javax.imageio.ImageIO; import sun.audio.*; public class Shooter extends JFrame{ int WIDTH = 500; int HEIGHT = 500; int x,y = 0; int height,width = 0; int health = 10; Rectangle p1 = new Rectangle(480, 210, 15, 100); Rectangle p2 = new Rectangle(0,210,15,100); public Shooter(){ super("Shooter"); setSize(WIDTH,HEIGHT); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBackground(Color.black); setVisible(true); } public class Player implements KeyListener{ public void run(){ addKeyListener(this); } public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) {} public void keyTyped(KeyEvent event) { if(event.getKeyChar()=='o'){ p1.y--; } } } public void paint(Graphics g){ g.setColor(Color.white); g.fillRect(0,210,15,100); g.fillRect(p1.x,p1.y, 15, 100); Rectangle p1 = new Rectangle(480, 210, 15, 100); Rectangle p2 = new Rectangle(0,210,15,100); } public static void main(String args[]){ new Shooter(); } }