Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jlabel rotation

 
surbhi grover
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have written a code to rotate a Jlabel but i am facing some problems. Can some one please help me out





 
Campbell Ritchie
Marshal
Posts: 52663
121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I had added code tags to youir post. Always use them: doesn't it look better now But you are mixing spaces and tabs for indenting which makes the formatting awkward.
Please tell us what is going wrong, otherwise we can't help you. What did you expect to happen and what actually happened?
 
Piet Souris
Rancher
Posts: 1641
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Surbhi,

indeed, what is the problem?

What I notice anyway, is that you are not adding your 'turningCanvas' to your frame.
Look at line 58, where you set the contentPane. Then, you let this variable point
to a new turningCanvas, but again: you do not add that to your frame.
I advise to take a close look at the lines 58-67.

Also, in your KeyboardListener, you should issue 'turningCanvas.repaint()',
once you have settled the current problems with this panel.

Greetz,
Piet
 
surbhi grover
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Ranch so i didnt knew about the code tags. Thank you for your help Campbell Ritchie.
basically i am new in java and i am working on my college project. I want the JLabel containing the image icon of the ship to be rotated and move using key listener left, right, up and down.
This code i had written is to rotate the Jlabel using key listener left and right at 360 degree while keeping the Jlabel at the center. But i am not getting any output. If any one could help me i would be indebted.
 
Campbell Ritchie
Marshal
Posts: 52663
121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

What do you mean by not getting output? Do you see the picture? Do you see it and it fails to turn? Have you taken note of PS's comments which will doubtless help you?
 
Swastik Dey
Rancher
Posts: 1689
7
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to adding listener to panel, but you should add listener to the frame
try this once

 
surbhi grover
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Thank you so much. You are awesome.
But i want this image icon be at center and rotate there
 
Piet Souris
Rancher
Posts: 1641
36
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must confess: I'm a bit annoyed. In my reply, I tried OP to focus on
the part of his code that was the cause of his problem. I also mentioned
the problem at hand.

@Swastik
if you supply ready made corrected code, at least explain
what you did and foremost, why you did it (i.e. what was the
problem).

Greetz,
Piet
 
Piet Souris
Rancher
Posts: 1641
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, I hope I didn't scare anyone off from replying. I may have sounded a bit harsh,
and if I offended or shocked anyone, I apologize.
But I see it all too often on this website:

someone replies, and

* adds really nothing to what has already been replied
* shows that he/she hasn't read what has already been replied, or worse: hasn't even read the
question properly.

I find such behaviour impolite towards earlier repliers and it annoys me. Can't help it.

Anyway, back to business.

@ surbhi:

well, it is fortunately not so difficult to center the image in your turningCanvas.

I give the somewhat changed code of your turningCanvas, with some comment
showing how to get it done. I did not use your image, but focussed on the
Label instead. Just replacing the Label by the image is all that is needed to get it
working for the image. So here goes:



Now you can resize your frame, and your Label will stay centered.

Greetz,
Piet
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!