Attempting to load out of an FXML scene into an FX scene - java

I made a bit of a mess when coding my program however do not have time to fix it before submission. My program opens up to a 3D molecule viewer for Water, Methane and Methyl, this is done without FXML and simply creates panes, borders, canvas and cameras which you can manipulate to view 360 around the molecule. One button on my side bar switches into an FXML Gui for a chemistry database, in which I want to display my SQL data.
However, once the scene has been switched I cannot switch back. I have attempted to reference the main class in the original starting .java through the FXMLController however it simply says that Handler method is not assesable, I add the #FXML and again nothing fixes. So Instead I attempted to make a public method which calls the main from the same class, this would work other than the fact that it now says that the handler method is not found.
I have searched high and low and cannot seem to find an answer. I am very new to java and javafx and would love to see this project through to the end.(Especially because completing this one simple(or not so apparently) function will complete my project bar loading the SQL database inside the GUI.
I will post a link to the FXML code and the class in which the main class is found.
Thanks
https://gist.github.com/anonymous/753797aeca8f12c8086628b740525625 --> FXMLDocument
https://gist.github.com/anonymous/60c58df1268aa5adeafca8faabf14c4c --> Class that has main(String[] args)

Related

Eclipse Window Builder importing classes

I'm working on a GUI in Window Builder and I want to import some of the objects I have declared on my main. The GUI is in the same package as my main and 5 classes, 1 parent and 4 child classes. Is this possible to do? As of right now, I'm trying to call my characters for the game I created into the GUI to be displayed when a certain button is pushed.
So far, I tried importing each class into my GUI. That didn't work went into my main and added my GUI by declaring it as a new object followed up by adding EventQueue.invokeLater and making that visible, but that didn't really work. Any thoughts on how to do something like this?
On Window builder Palette, click choose component and search for your class for example
package.class. This is the image Refer to this.

JavaFX switch scenes / screens / app in main BorderPane

Here is the problem,
I have a JavaFX application, main display element is a BorderPane.
I use the top of the BorderPane to display buttons, that will act like "navigation" buttons, and the center to display the current chosen application part.
Some solution, described on this link should do the trick :
https://community.oracle.com/thread/2598756
I'm really confused about the code, The only thing I really understand here is that it sets up some kind of changeListener on a list, supposed to hold the "selectedView".
Once the list changes, it triggers a function in the main part of the application, and this fuction SHOULD set the center element display with a new fxml file loaded.
So, I tried to implement quite the same example, only with 2 levels (main -> center) and get nothing working.
Here are the current files I created :
ScreenSwitcher.java
// Main class, loads the "main" fxml component
Main.fxml
// Main fxml component, BorderPane (buttons + center -empty-)
MainController.java
// Main controller, the magic should happen here
PaneOne.fxml & PaneTwo.fxml
// Children fxml, should only be displayed in the main->center element
PanelOneController.java & PaneTwoController.java
// Corresponding controllers
ViewControllerInterface.java
// An interface, as described in the given link explanation
https://github.com/Julo0sS/ScreenSwitcher
First, at app starting, I get this warning :
WARNING: Exception while evaluating select-binding [selectedView]
Then, when clicking on a button to switch the main display, nothing happens... I do have the console showing "CALL TO GOPANEWO" (or GOPANEONE), so it goes into the function code, but seems like the "changeListener" does not work...
Maybe I'm just wrong in the code, maybe there's a better/faster way to achieve what I'm trying, but actually, I'm just stuck on this...
Thanks for reading / help
Update One
Can get a part of the app working now,
The change currentView "event" is sent, and works correctly, WHEN sent by the child view itself (by click on a button in PaneOne, or PaneTwo), but does NOT work when triggered in the main view (in the top part of the borderpane, which is supposed to be a navbar)
Git repo updated with latest modifications...

JavaFX: Working with elements within another class

So the generally Idea I have is having a basic JavaFX app. So I make a new project and it has the default stuff such as
#Override
public void start(Stage stage) throws Exception
{
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
and it has the basic button that when you click it prints hello world. So so far all i am trying to do is show you it is a basic default project.
now lets assume I have another class. Lets say that class runs on another thread and that when I type in a name into the console (in my case NetBeans) then it will update the button to say something else.
This is very general, I been googling and trying things with no perfect result. In hindsight, I am trying to make it so, I can have other classes edit the FXML document or elements on the page, then it will show on my program. I am not sure if I have to reload the FXML doc or reload the stage or what. I just wnat a guide or help on how to reference and change stuff around on a JavaFX FXML program. I been working on a chat program and been using normal Javafx with NO FXML and run into problems. So I am thinking about doing it on FXML. but I have times where I a class handle the user names and a class handle the messages for everyone to read and I need these classes to be able to edit the FXML document and reload it to show up. SO, if i user connects to the server, for example, the ListView object will now show that person name. like I said before, I have been able to do this working with Javafx without an FXML file, but my code is like spaghetti. Thanks in advance

Hybrid application not showing scroll bar

My WL6.1.0.1 hybrid application have an overflow (with css set to -webkit-overflow-scrolling: touch) which scrolls just fine, but I don't see the scroll bar, neither the android feedback when I hit the bottom of the scroll (that glowing light that android have).
Curiously enough if I access the same application via "Common Resources" using the chrome browser on my android device, both the scroll bar and the feedback shows up.
I added the following code to my main java class on the native side (the one that extends WLDroidGap and have the app name)
public void onWLInitCompleted(Bundle savedInstanceState){
super.loadUrl(getWebMainFilePath());
// Add custom initialization code after this line
this.appView.setVerticalScrollBarEnabled(true);
this.appView.setVerticalScrollbarOverlay(true);
}
But it still doesn't work, any ideas?
For the "feedback", you are probably referring to EdgeEffect (when reaching the bottom of the view). If so, it is working for me like this:
public void onWLInitCompleted(Bundle savedInstanceState){
super.loadUrl(getWebMainFilePath());
// Add custom initialization code after this line
this.appView.setOverScrollMode(appView.OVER_SCROLL_ALWAYS);
}
You can set this in the onCreate as well...
For showing the scrollbar, I think you need to use awakenScrollBars() in combination with setVerticalScrollBarEnabled.
That said, I don't know the use case of your app, but typically in an app you would not want a scrollbar unless specifically in a list or something like that (and maybe not even there...).
Additionally, because you are developing a Hybrid app in Worklight and may target additional environments there are alternative solutions instead of delving into native code, such as using iScroll which can take care of much more than just scrolling, but also the "bounce" effect and other things.

Getting Java Applet to play as standalone Application

I've spent the last few days putting together a game that runs as an Applet, but I would also like to have it available as an Application.
I've tried placing the applet in a frame, but I only get a black screen (and the occasional menu screen) when doing so. The applet still runs and the sound still plays, but there is nothing else.
I would like to not have to break down the code and rewrite it for a standalone application, as it's time consuming, but if there's no other way, then I'll do what I have to do. The program is a little complex in that the "main" class (containing all the media information, game related events, etc.) is an extension of an Applet class (containing the KeyListener, init() event, run() event, etc.) so maybe I am just trying to place the wrong thing in a frame?
Here is a link to the src folder for the game. I have tried putting both the AWPASG class and the Game class in a frame and seen the same results for both.
Any help would be greatly appreciated.
Source Code/Media
http://www.mediafire.com/?4eslqqr4aoh33j1
That's because your class design is not very good. You've bunched everything together in 2 classses, isntead of separating at least the UI Widgets (panels, etc, etc) from the UI Container.
Also you're using the old style AWT Applet and Panel. You should use the new Swing JApplet and JPanel (and all opthers JXxx components)
In short, try isolating your GUI building (painting) into a class that extends JPanel (or contains a JPanel). Then you can have 2 separate startup classes, one that puts your game JPanel inside a JApplet and one that puts it into a JFrame (and thus gives you the possibility to start it as a Desktop application).
Also you might want to separate your GAME init logic from the Applet init lifecycle, your game should be able to initialize without caring about the underlieing GUI technology.

Categories