• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Snow Falling by button  RSS feed

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have found a Snow Falling effect class which I've been looking for. I have 2 themes: a classic theme and a Christmas theme. These themes can be changed by clicking on a button. Is there a way to make sure this snow only falls in my Christmas theme once this is loaded, and if so, how?

Thanks!

Snowfall code:


FXMLController code:
 
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lol still working on your pacman game?
You say you found a snow falling effect class, what do you mean by that?
Nowhere in your code is see you using such a class?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about this repository?
I guess you following this tutorial?

Making sure they only wil be created when you switch to christmassstyle isnt that hard, put the code in your function called by your button, once it's created switching back to snowless, might not be so easy
You could modify this part:

of the rainig method instead of just looping you could let it check if the stylesheet being used still is the xmass one
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Are you talking about this repository?
I guess you following this tutorial?

Making sure they only wil be created when you switch to christmassstyle isnt that hard, put the code in your function called by your button, once it's created switching back to snowless, might not be so easy
You could modify this part:

of the rainig method instead of just looping you could let it check if the stylesheet being used still is the xmass one


Yes I'm using that repository! I still really don't know how to implement it, do I put the snow code in my main? Or what? Could you help me out a little using my code above? Or do you need my main's code too?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Axel Rey wrote:
Yes I'm using that repository! I still really don't know how to implement it, do I put the snow code in my main? Or what? Could you help me out a little using my code above? Or do you need my main's code too?


If you want it only to snow when you selected the xmassStyle, you can't put in your main. Like I set before you need to put it in your method that you call to switch css, checking what stylesheet is being used.
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:

Axel Rey wrote:
Yes I'm using that repository! I still really don't know how to implement it, do I put the snow code in my main? Or what? Could you help me out a little using my code above? Or do you need my main's code too?


If you want it only to snow when you selected the xmassStyle, you can't put in your main. Like I set before you need to put it in your method that you call to switch css, checking what stylesheet is being used.


Also please note that I want it to be some type of overlay, as it should be playing in the background continuously, while still able to use buttons and etc on panes.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Axel Rey wrote:
Also please note that I want it to be some type of overlay, as it should be playing in the background continuously, while still able to use buttons and etc on panes.


Then you will have to set the rest to the front. If you maded that comment in the hope I would write a solution for you, I'm not gonna do that.
It's bin brought to my attention that I spoonfeed to mutch, and I don't want to rob you'll of the fun of learning yourself.
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:

Axel Rey wrote:
Also please note that I want it to be some type of overlay, as it should be playing in the background continuously, while still able to use buttons and etc on panes.


Then you will have to set the rest to the front. If you maded that comment in the hope I would write a solution for you, I'm not gonna do that.
It's bin brought to my attention that I spoonfeed to mutch, and I don't want to rob you'll of the fun of learning yourself.


Won't that mean that the snow just won't show as the other panes and etc are in front, blocking its view?
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I've added the lines as you said, I made an AnchorPane called 'snow' in my FXML and changed the code in the controller to:


and added this line to the main:


But it still doesn't seem to be working..
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you set your panes to the front, they will before the snow, so the snow won't block the view, you might have to set your panes backgroundcolor to transparrent or they might block the snow.
You could actually try that, it might be a solution to your prob. If setting the panes to the front with normal background blocks the snow, you only have to change one line in your cssfile, setting the background to transparrent in your xMass.css and giving them a color in your general
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First just try to make the snow fall, before trying to hide it in one of the two css files
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now you have a boolean that decides if it should start snowing, not when it should stop, the loop is still being called.
You need to modify this part:
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:now you have a boolean that decides if it should start snowing, not when it should stop, the loop is still being called.
You need to modify this part:


So I just checked: I turned my boolean to true and the snow is falling! The problem now is that it's quite laggy.
I will still have to fix the button thingy.
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Axel Rey wrote:

Daniel Demesmaecker wrote:now you have a boolean that decides if it should start snowing, not when it should stop, the loop is still being called.
You need to modify this part:


So I just checked: I turned my boolean to true and the snow is falling! The problem now is that it's quite laggy.
I will still have to fix the button thingy.


I tried this:

but it gives me this error: non-static method getXmasTheme() cannot be referenced from a static context
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you'll have to set two variable pathToXmass and pathToCurrent in the beginning of the rin method and comapare those  in the static method
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Then you'll have to set two variable pathToXmass and pathToCurrent in the beginning of the rin method and comapare those  in the static method


Like this?
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Axel Rey wrote:

Daniel Demesmaecker wrote:Then you'll have to set two variable pathToXmass and pathToCurrent in the beginning of the rin method and comapare those  in the static method


Like this?


This doesn't seem to work, there's something wrong with my pathToCurrent String.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like:


You actually dont need the pathToXmass, you could do:


But once again, I'm not sure this will work, it's an educated guess...
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Like:


You actually dont need the pathToXmass, you could do:


But once again, I'm not sure this will work, it's an educated guess...


Seems to be giving me a NullPointerException at this line:
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:try using


Unfortunately doesn't help, still the same nullpointer.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give me a sec, I'm doing some workstuff, later I can help you finding a solution...
I'll try to implement the snow myself...
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Give me a sec, I'm doing some workstuff, later I can help you finding a solution...
I'll try to implement the snow myself...


Take your time, I'll be here once you're finished working =). Thanks for the help so far!
 
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

still the same nullpointer.


Where is the null value?
Break up that long chained statement and print out each part to see where the null value is.
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

still the same nullpointer.


Where is the null value?
Break up that long chained statement and print out each part to see where the null value is.


Goes null after
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works:



You'll just have to fidle with the duration a bit, so it stops faster when you switch css
 
Norm Radder
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Goes null after

SideMenu.getStage().getScene()


Are you saying that the getScene method returns a null value?
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

Goes null after

SideMenu.getStage().getScene()


Are you saying that the getScene method returns a null value?


Yes it does! The fix Daniel proposed didn't work either.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Axel Rey wrote:
Yes it does! The fix Daniel proposed didn't work either.



Yes it does... I used the project I maded when you asked how to switch stylesheets and succeeded in implementing it. But like I said, you need to fide with the config a bit to make it stop faster...

 
Norm Radder
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the API for getScene to see when it returns a null value?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't just copy paste my code right?
I use the scene of the static stage defined in my Main.class, while you use the stage of sideMenu, so you'll have to adjust that
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:You didn't just copy paste my code right?
I use the scene of the static stage defined in my Main.class, while you use the stage of sideMenu, so you'll have to adjust that


I adjusted that but that still gives me a NullPointer when I try to getScene() there. So at this line, the .getScene():
 
Norm Radder
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the API for getScene to see when it returns a null value?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In several places in your code you have

Why not deining it once a the top of your controller and use that in the rest of your code? Normally that shouldnt give you the nullpointer, but still. When Im home, I'll post my whole project so you can set where it differs.
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Did you look at the API for getScene to see when it returns a null value?


How do I do this exactly? I'm not really used to doing those kind of things.
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:In several places in your code you have

Why not deining it once a the top of your controller and use that in the rest of your code? Normally that shouldnt give you the nullpointer, but still. When Im home, I'll post my whole project so you can set where it differs.


I already tried doing that, that didn't work either! For some reason it returns a null in this specific method.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post your current raining methode?
 
Norm Radder
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How do I do this exactly?


Here is a link to the JavaFX API doc: https://docs.oracle.com/javase/8/javafx/api/
At the top of the page click on the INDEX link, then click on G for the first letter of the method, search for the method: getScene, then click on the link for that method and read its API doc.

Or if you know the name of the class that getScene is in, find its name in the left hand window, click on it and then scan down to the API doc for the getScene method.
 
Axel Rey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Could you post your current raining methode?


Current:
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way... you are sure you're hing the correct methode and didnt by accident importen the wrong class?
 
Do not set lab on fire. Or this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!