2 Basic Questions....
Ive done alot of reading to get some basic applet creating knowledge,
however I have 2 questions: What happens when a shape goes off and you
cant see it anymore? Is it possible to destroy is when it leaves the
screen or do I need to reuse it?
And how would I create an array of rectangles?
I want to just go forward/ or backwards for what seems forever, run my
applet and you'll see what i mean.
My Code so far:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class KeyboardTest extends Applet implements KeyListener {
int keyCode;
int x = 100;
int y = 100;
int width = 75;
int height = 100;
public void init() {
addKeyListener(this);
}
public void paint(Graphics g) {
g.drawRect (x-50,y-50,width+100,height+100);
g.drawRect (x,y,width,height);
g.drawRect (x+50,y+50,width-100,height-100);
}
public void keyPressed(KeyEvent e) {
keyCode = e.getKeyCode();
if(keyCode == 38)
{
x--;
y--;
width = width +2;
height = height +2;
}
else if(keyCode == 40)
{
x++;
y++;
width = width -2;
height = height -2;
}
repaint();
}
public void keyReleased(KeyEvent e) { }
public void keyTyped(KeyEvent e) { }
}