• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Drawing in Canvas choosing tool in Gridpane

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
eqw5Z.png
[Thumbnail for eqw5Z.png]
 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi and Welcome to the Ranch!

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.
 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, I see you've post your own solution.  It looks good!

About your second post: please UseCodeTags (that's a link).  Basically highlight a class and press the code button.  I've given you the ability to edit your post so you can try it out.
 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, two more things about posting code.  If the classes are something you want us to run, then please include the import statements.

Second, please format your code correctly.  Indent everything properly and remove all but one empty line.  On an IDE this is easy.  On Eclipse it's just Ctrl-Shift-F.

Edit: You have several imports that custom jars, I believe.  Classes like DrawEvent, and CustomizedButton.  How do I get these jars?
 
davide agoletti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Thanks
 
davide agoletti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 😂
 
davide agoletti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, that doesn't sound like it would work.  Why do you need custom events and buttons?
 
davide agoletti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
davide agoletti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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





request
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 ??

 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd play around with the Path and maybe a PathTransition, but honestly, I'm not sure how it would work.
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic