I am attempting to recreate Wheel of Fortune in Java. What I have been thinking about doing is creating a wheel, and rotating the image and randomly stopping. But, I don't know how to rotate a JLabel. I am using NetBeans JFrame creator.
I can't really provide code, as this is just a concept in my head right now. I am planning to set the JLabel's icon to the wheel. I need to be able to rotate a JLabel at a button press, and stop at random. It then, needs to read the rotation value of the JLabel, so it can read the amount of points you win. Is this possible?
Yes, I have researched. All the other rotating JLabel forums do not show how to read the rotation value.
I am a beginner in Java. Any help is appreciated! :)
I am planning to set the JLabel's icon to the wheel. I need to be able to rotate a JLabel at a button press
Don't rotate the label, instead you can just rotate the Icon.
Check out Rotated Icon. You just specify the angle of rotation and it will paint the Icon rotated. You can use the getDegrees() method to know the current rotation at any time.
Related
I am trying to implement the panning. I've a subScene with perspective camera and a Box inside it. I am able to pan the box relative to the camera (So camera is fixed and the box moves left right-left-top-down). How can I achieve panning by not moving the box relative to the camera. Is there any way to move the camera inside the subScene(Usually its position is fixed).
The problem in my current approach is that when I pan the box to left, its right face is revealed more because of the perspective. It seems like the box rotates a little bit on pan. I want to remove this slight rotation effect on panning for which I need to pan the box and camera simultaneously in same direction (without any relative movement between them). But I am not able to figure out how to move the camera as the camera position is fixed with respect to the subScene.
Thanks.
I'm making a game and when I add my sprites to my screen, naturally, they are behind my mouse. But I want to add a custom mouse image to my screen, over the mouse.
I already have sprites for the mouse, and I know to to make the image appear wherever my mouse is. The only thing is that I already know its going to appear underneath my mouse. Any suggestions?
Set the image as a custom Cursor. See Toolkit.createCustomCursor(Image,Point,String) for turning the image into a cursor.
The knob of the JSlider originally has only 1 degree of freedom (it translates on the track either horizontally or vertically). I want to add a 2nd degree of freedom to the knob and manually rotate it. In other words, I want to be able to move the knob left and right AND rotate it. Both of these movements should be able to be set by either dragging the mouse in a linear or rotational direction. I havent seen code for this and was wondering how I could go about this.
I'd extend BasicSliderUI and override the paintThumb method so that you can paint your thumb at an arbitrary rotation, either by applying a rotation transform to the thumb image, or by manually drawing the thumb rotated. Then apply this UI to your JSlider.
To control the rotation with the mouse and keyboard, it may be easiest to add a MouseWheelListener to the JSlider so that you control thumb rotation with the mouse wheel.
In Java, is it possible to use paintIcon to put an icon into a canvas, and then move that icon around using keyboard events like you would a game character?
Once you paint something on the canvas, it stays there, and what was there beneath that location is lost. To "move" the icon, you need to repaint the canvas (or at least what was originally at the location of the icon) and draw the icon at its new position.
This would work better with an applet by registering keylisteners.
and overridding the paint method
I am working on a project in which I have a background image with specific points of interest. Each of these specific points will have a custom button class overlaid on it so that when I click the point, I'm actually clicking the button. However, I would like to be able to rotate the background image and have the buttons rotate with the image so that the custom buttons are still overlaid on the specific points. Any tips as to how I should go about doing this?
Are you actually wanting to rotate 4 different images and move them around the square, but always keeping them upright? Or are you rotating a single image so that after one button click the single image is on its side? If the former, then that can be easily done by using a container (a JPanel) that uses BorderLayout, and having four JPanels with background images and JButtons held in the container JPanel at the four compass points of the BorderLayout: BorderLayout.EAST, BorderLayout.WEST, BorderLayout.NORTH, and BorderLayout.SOUTH (although Java gurus prefer you use the newer constants, i.e., BorderLayout.PAGE_START). Then when a button is pressed, remove components and re-add but in a rotated order.
If you want to do the latter, then things get a bit trickier in that you'll likely need to use AffineTransforms, rotate instance to rotate the container, and you'll need to perform the same transformation on the point of the mouse press/click/release, so that the rotated buttons receive correct clicks. If the container is not square, things get even trickier still.