/help
I'm trying to create a program with javaFX which generates 10 different shapes (lines, squares and ellipses) everytime I press a buttom.
The shapes suppose to get a random color.
I already managed to create the code which generates 10 different shapes as asked BUT I don't manage to color them no matter what I do.
How can I color them?
------------------------------------------------------------------------------------------------------------------------------------------------
I'n the picture I sent, this is the code which generates ellipses, it generates them black, now I just need to color it.
I've made 3 variables which get values between 0 to 255 to represents the RGB shades.
I don't know which command color it, I tried to find an answer for hours
thanks!
26 Replies
β
This post has been reserved for your question.
Hey @Yarden! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Of what type is your shape object?
Oval
I did gc.fillOval(...)
I guess i'm missing your question
the object
gc
canvas
what type is it
If it can help
But yeah the object is canvas type
Or maybe you mean GraphicsContext?
hm
gc is a graphicContext
But I initialized in with canvas
So when I use gc, I'm actually mianly drawing on the canvas
that's what I meanπ
this also doesnt work with a hard coded colour?
Why do you mean hard coded colour?
Sorry I'm fresh with javaFX
Color.BLUE
for exampleIt doesm but I need a random color
does*
When I do the RGB it causes the shapes to disappear
does it also work with hard coded values like
Color.rgb(255, 191, 0)
I'm stupid...
I coded it wrongly in the color generator...
it works
yeah thought so π
I wrongly did
int color = random.nextInt() * 255;
instead of int color = random.nextInt(255);
when you have a problem like this
thank you very much and sorry for wasting your time
you helped me much
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
try to make it less complex first
I will
thank you!
so you can figure out where the problem lays
no worries
good luck in the future
thank you!
Post Closed
This post has been closed by <@218019068219883520>.