Hi guys i need an help ,in attachments i have put an image of my project , in essence I want to draw in a canvas different kind of shape like a line,circle,rectangle ,triangle ecc when i click the relative button, I'm new on the javafx programming , and for now what i have understand it is that the canvas can only modify in the main Thread of the GUI ,and this is the problem , because when i handle the button event "SetonAction" i need a reference of the main canvas to draw line or cirlce ecc. I have try with a new Thread but without success.
If anyone Know a way to do this , i really appricieted.Thanks in advice
I'm not sure your solution requires posting on a new Thread, but here it is. Unfortunately it is not a trivial process.
So the UI is very simple because I'm trying to illustrate how to get a process on another Thread.
* Press Start and the countdown from 10 begins
* To prove that the UI is still responsive, push the On/Off button a few times.
* Press the Close button and the app closes without hanging
In the code I've labeled two sections with the comment "This is the good part." By that I mean, This is what you should notice. Even though it's very simple, most of the code is UI.
All things are lawful, but not all things are profitable.
Thank You knute !!!Yes sorry the code It was written in a bad way,but It was Only for a code test ,then i pass to the 2 phase for separate the code in different classes .
And sorry for missing the tag ,but i don't write a lot in forum and i'm not usually to use the tag.anyway tomorrow i'll try to adjust It with PC ...because now im responding with smartphone.
About the thread ,i have read in some book or in some post ,that the graphics context that You can retrive for drawing in a canvas it's editable ONLY in the main thread of GUI ,...i'm a Little bit confused about ...i have to study It better 😂
About the import not used... the first attempt I was thinking to :
1)create a custom event and relative handler
2)extends Button class with additional code for handler the custom event
3)Fire the custom event inside the handle of "setonmousepressed" for advise the listener of canvas(that can handel the custom event)that can draw the specific shape..
But It was a bad idea because... the compiler does not digest it...composite event error.
I was thinking to put inside custom Button additional information for recognize the type of Button pressed and Only in a second moment i realized that this It wasnt necessary.
Anyway here are 2:00 A.M . Goodnight thanks for helping me!!!
YEAHHH !!! i found a solution and i was able to separate the classes!!! take a look above and tell me what you thinking about
this it was the main classes ,here the other classes
now i need a little bit of help , this is the project for mine exams of software engeneering , in the requests of the projects there is the possibility to change every side of the polygon that i have draw , my idea it ii
1)put an effect of transition (o sort of marker effect )when the mouse is on the side Interested. and i don't know if is the case to find a preventiv way to close the shape.
2)change dinamically the shape .
For the second point i think it was better using the "Path " construct ...can you help me ??