This discussion is archived
7 Replies Latest reply: Jun 27, 2011 6:01 AM by 605553 RSS

Tips

605553 Newbie
Currently Being Moderated
Hi all

I am beginner at JavaFX and I want to develop an application that uses many screens, one for login and others that changes depending on button click etc. Do anyone has an example like as that I want to develop to use as guide? Not a media application, but something as such as commercial application.

Thanks for any kind of help or tip

Ricardo
  • 1. Re: Tips
    805536 Journeyer
    Currently Being Moderated
    JavaFX is still sort of experimental, and there aren't a lot of sophisticated examples out there. The official examples are located here: http://javafx.com/samples/ . The only one I know of to switch screens is this one here: http://javafx.com/samples/BrickBreaker/index.html . What it basically does is switch the Node representing one screen with another. Here is a simpler example that does something similar:
    import javafx.scene.*;
    import javafx.stage.*;
    import javafx.scene.shape.*;
    import javafx.scene.control.*;
    import javafx.scene.paint.*;
    
    var screen1 : Node = Rectangle {
        width: 500
        height: 300
        fill: Color.BLUE
    }
    
    var screen2 : Node = Rectangle {
        width: 500
        height: 300
        fill: Color.RED
    }
    
    var button : Button = Button {
        text: "Next Screen"
        action: function() {
            //Remove the old content and replace it with the new.
            scene.content = screen2;
        }
    }
    
    var scene : Scene = Scene {
        content: [
            screen1,
            button
            ]
    }
    
    var stage = Stage {
        width: 500
        height: 300
        scene: scene
    }
  • 2. Re: Tips
    605553 Newbie
    Currently Being Moderated
    Thank you aidreamer.

    I just want to know how the things happen in javafx. Using your example, if I want to maintain the button and do the same, when screen is red I click on it and change to blue again, I have to define the button again?

    Tks
    Ricardo
  • 3. Re: Tips
    805536 Journeyer
    Currently Being Moderated
    You could do that. Generally speaking however, I would make each screen a custom node. Each custom node would presumably have its own child nodes, such as a screen switching button:
    public class ScreenOne extends CustomNode {
        public var width : Number;
        public var height : Number;
    
        public var scene : Scene;
    
        //These nodes define what the custom node will look like.
        override var children = [
            //Background
            Rectangle {
                width: bind width
                height: bind height
                fill: Color.BLUE
            },
    
            //A button to switch to some other scene.
            Button {
                text: "Switch screen"
                action: function() {
                    //Switch the scene's node with some other scene node.
                    scene.content = ScreenTwo {
                        width: bind scene.width
                        height: bind scene.height
                        scene: scene
                    }
                }
            }
        ]
    }
  • 4. Re: Tips
    abg Newbie
    Currently Being Moderated
    Hi Richardo

    I started like you thinking different scenes but found, as you have, that you need to replicate controls that do the same thing on different scenes. If you look at the demonstration on my website www.eco-wand.com. you will see that, as you select different displays, something change but others stay the same. This is all done by using the "visible" attribute of each of the elements or groups.

    If you click on the eco-bar select button, you get a quite different size of display - this is using a scene change.

    For each of the the display buttons, the function set a variable called displayindex

    For each of the groups there is a line in the form of:

    visible: bind displayindex == 0

    when displayindex is 0, that particular group is displayed.

    Hope this helps

    How I will convert all this to javaFX2 I don't know. I may have to change to Visage if it works.

    Alex
  • 5. Re: Tips
    605553 Newbie
    Currently Being Moderated
    Thank you Alex for your suggestion.

    I think that my concept about how javafx runs is wrong. I understood how you show a screen using a variable to control it, but if I have a desktop application that the user have to connect to application to setup some informations. This connection will be into a database. I though to create an login screen. After that, i will show the application. In JavaFX, I create a class login.fx (for instance), to do a connection with a scene? At the application, for each screen I have to create a specific fx class, this is, a scene? Then, I have to create a "main" class to call all others depending on selections, controls. Is correct to think in this way?



    Ricardo
  • 6. Re: Tips
    DarrylBurke Guru Moderator
    Currently Being Moderated
    A few days after this thread started, Oracle launched the first public beta of the JavaFX 2.0 SDK. Since you haven't even started learning JavaFX script (aka 1.x) I suggest you learn 2.0, which uses Java syntax, instead. Here's the home page: http://download.oracle.com/javafx/index.html

    db
  • 7. Re: Tips
    605553 Newbie
    Currently Being Moderated
    Darryl

    I have seen something about this new release and I liked too much. But I have been used linux (ubuntu) to develop my applications and there is no version to linux yet.
    Anyway, I can try to install that version with Nb 7 into a virtual machine (windows 7) in linux.... it is an alternative.

    I will try to do it, thanks a lot

    Ricardo

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points