adding graphic objects to JPanel
posted 14 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Dear JavaRanch,
i recently stepped into the world of java programming leaving my short by enjoyable Python roots behind.
it was not long untill i started to bump into difficulties.
like now for instance, i'm trying to make a ball appear on mouseclick that circles around the cursor.
now i got 2 things that i cant stand.
1, the offset of the ball is odd, its not located in the middle and i tried adding/substracting half of its size to the X,Y.
2, how do i make the ball (or a multiplicity of which) appear without inviking errors like NullPointerExeption.
here comes my code, dont know bricks about text formatting on forums yet
sorry for the mess and the lack of commenting.
and for the Skwer object that i want to make appear.
now where and how do i get n error free ball on my screen by the click of a mouse?
i recently stepped into the world of java programming leaving my short by enjoyable Python roots behind.
it was not long untill i started to bump into difficulties.
like now for instance, i'm trying to make a ball appear on mouseclick that circles around the cursor.
now i got 2 things that i cant stand.
1, the offset of the ball is odd, its not located in the middle and i tried adding/substracting half of its size to the X,Y.
2, how do i make the ball (or a multiplicity of which) appear without inviking errors like NullPointerExeption.
here comes my code, dont know bricks about text formatting on forums yet
sorry for the mess and the lack of commenting.
and for the Skwer object that i want to make appear.
now where and how do i get n error free ball on my screen by the click of a mouse?
posted 14 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
First things first, the reason why your ball isn't at the center of your cursor is because your mouse listeners are registered to a JFrame object, a JFrame is the whole window frame so the 0,0 coords are actually at the top left corner of the frame (above the java icon). Add the mouse listeners to the Skwer object instead
or make a JPanel inside the JFrame and register the listeners to it instead
or make a JPanel inside the JFrame and register the listeners to it instead
posted 14 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I shall move this discussion to the GUIs forum, where it would fit better.
And welcome to the Ranch )
And welcome to the Ranch )
Campbell Ritchie
Marshal
Posts: 81617
593
posted 14 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Have you considered a MouseAdapter or MouseMotionAdapter which might avoid your having to write seven methods? Make sure to use the @Override annotation with your overridden methods.
frank van schie
Greenhorn
Posts: 7
posted 14 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
oh i see.
i shall try these suggestions when i get access to my machine again!
thanks in advance!
i shall try these suggestions when i get access to my machine again!
thanks in advance!
frank van schie
Greenhorn
Posts: 7
posted 14 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
OK, well that worked.
But i still have no clue on how to add (multiple) Skwer objects on my JPanel.
like uh
for instance i'll make an InvertedSkwer object that moves in the direct opposide direction when i move the mouse
and preferable have it appear when i click the mouse or something.
But i still have no clue on how to add (multiple) Skwer objects on my JPanel.
like uh
for instance i'll make an InvertedSkwer object that moves in the direct opposide direction when i move the mouse
and preferable have it appear when i click the mouse or something.
| She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |









