These will prevent it from being moved off the edge of the frame X and Y coordinates of square (top left corner), and the factors by which it will move or resize each timeĭouble xPos = 0, yPos = 0, movementX = 0, movementY = 0 Import class MovingSquare extends JPanel implements ActionListener, KeyListener This is the code to set up and draw the square: import javax.swing.* Not really sure what is going wrong here. I have put controls into my code to try stopping the square, but they don't seem to be working. If I move the square to the edge of the frame it keeps going and moves right past the edge of the screen. It moves around fine when I press one of the arrow keys, but if I move it to the edge of the frame, I want it to stop. I have a program to move a square about using the keyboard.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |