I am trying to create a Also see it inside JPanel with arrow keys. It does not work, I believe that this is my internal class which increases the
KeyAdapter I'm not even sure that
ActionListener was implemented The square I have created does not matter because it is just the frame
package, JerryWorld; Import javax.swing *; Import java.awt. *; Import java.awt.event. *; Public class Jerry JPLNL applies ActionListener {int SizeX, SizeY, PosX, Posy, Velx, Vely; Image image; Timer time = new timer (1, this); Public Jerry () {Image I = New Immune (); AddKeyListener (new AL ()); Time.start (); Img = i.getImage (); PosX = 375; Posy = 250; } Public Zero Color (Graphics G) {Graphics2D g2d = (Graphics2D) G; G2d.fillRect (PosX, Posy, 50, 100); } Public Zero Functionality (ActionEvent e) {PosX = PosX + Velx; Repaint (); } Private class provides AL KeyAdapter {public zero keypress (KeyEvent e) {int key = e.getKeyCode (); Println ("yay!"); If (key == KeyEvent.VK_LEFT) VelX = -1; Else if (key == KeyEvent.VK_RIGHT) Wells = 1; } Public Zero Key Relayed (Key Event E) {int key = e.getKeyCode (); If (key == KeyEvent.VK_LEFT) Wells = 0; Else if (key == KeyEvent.VK_RIGHT) VelX = 0; }}}
paint (...) rather than
paintComponent (...) unless you are sure that you Want to override component boundaries and children's painting (you do not).
paintComponent (...) .
No comments:
Post a Comment