When you create an instance of Square, you need to pass a reference to the instance of simplegraphics which created it. The easiest way to do this is in the constructor:
Code:
public class Square extends JFrame{
int x = 50, y = 50, xsize = 100, ysize = 100, xvel = 1, yvel = 1, speed = 1;
simplegraphics myParent;
Square (simplegraphics daddy) {
myParent = daddy;
}
void move() {
if(x > myParent.getWidth()) // this
xvel = -xvel;
if(x < 0)
xvel = -xvel;
if(y > myParent.getHeight()) // and this. Are my problems.
yvel = -yvel;
if(y < 0)
yvel = -yvel;
x = x + xvel;
y = y + yvel;
}
}
Don't forget in simplegraphics to pass the instance when creating Square:
Code:
Square MySquare = new Square(this);
I ran this in NetBeans and got a nice bouncing box.