Jump to content

How do I move jLabel within a jPanel?

RageAx

I'm trying to do a simple pong game in netbeans java. I have selected jLabels for my platforms, let's call them, and i have no clue as to how to move them up and down with a keyboard. I am very recent to java and my skills are poor to say the best. Please help me.

Link to comment
Share on other sites

Link to post
Share on other sites

I'm trying to do a simple pong game in netbeans java. I have selected jLabels for my platforms, let's call them, and i have no clue as to how to move them up and down with a keyboard. I am very recent to java and my skills are poor to say the best. Please help me.

 

I don't know java put you should write some pseudocode that normally helps.

if up key pressed   Move panel up along Y axisend ifif down key is pressed    move panel down along Y axisend if

you need to check for key input and then move the position as needed.

 

Found this on google, http://stackoverflow.com/questions/18037576/how-do-i-check-if-the-user-is-pressing-a-key

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Swing elements aren't really meant to be used like that. You should create a class that extends JPanel and override the paintComponent method to draw your own rectangles.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×