To be perfectly honest, I think Java is not something you should program anything in at all.
But I feel your pain, I managed to learn ActionScript and even published a game in it just before Flash has died.
To take your question more seriously, if you've already far into a project in Java, then finish it. If you package it nicely, people may still play it – if you think about it, people still play Java games, think about Minecraft. But if you're just about to start something, I'd definitely recommend something else. In case you want your game to be playable in the browser, consider HTML5 + JavaScript or WebAssembly. There are even some nice game engines so you don't have to start from scratch, I tried Phaser (JS) and it's quite capable. In case your game is supposed to be downloaded and played directly, then you can use game engines like Unity (though I don't have experience with it), or use programming languages like Python or C++ (game engines exist for these languages). I recently got into Rust and I think it's the programming language of the future: it's memory safe, performant, doesn't have an ugly garbage collector, and supports a variety of platforms (including WASM, so it's actually great for web development also); the only drawback is that there are no fleshed out game engines as of yet (though you can still try Bevy), and it's only recommended if you already have great experience with programming, including system programming languages, because it introduces some new concepts like lifetimes those only make sense if you know about the possible pitfalls of memory management it is protecting you from.