JavaFX to realize desktop application interface Jump __java

Source: Internet
Author: User
Tags visibility

Can only be implemented, but this jump method is not a specification I am not very clear

For example: Click Jfx2.java to create a button on the stage to jump to the stage created by Jfx3.java




The code is as follows:

Jfx2.java

Package review;
Import javafx.application.*;
Import javafx.scene.*;
Import javafx.stage.*;
Import javafx.scene.control.*;
Import javafx.scene.layout.*;
public class JFX2 extends application
{public
	static void Main (string[] args)
	{
		launch (args);
	}

	@Override public
	void Start (Stage Stage) throws Exception {Stackpane pane=new stackpane
		();
		
		Button Button=new button ("Open another Stage");
		Button.setcursor (Cursor.hand);
		Button.setonaction (e->{
			Jfx3 open=new Jfx3 ();
			Try
			{
				Open.start (new Stage ());
				Stage.hide (); 
			} 
			catch (Exception E1)
			{
				e1.printstacktrace ();
			}
		});
		
		Pane.getchildren (). Add (button);
		
		Scene scene=new Scene (pane,300,200);
		
		Stage.setscene (scene);
		Stage.settitle ("Demo");
		Stage.show ();
		
	}

Jfx3.java

Package review;
Import javafx.application.*;
Import javafx.scene.*;
Import javafx.stage.*;
Import javafx.scene.control.*;
Import javafx.scene.layout.*;
public class Jfx3 extends application
{


	@Override public
	void Start (Stage Stage) throws Exception
	{
		Stackpane pane=new Stackpane ();
		
		Label Lb=new label ("This is a new stage");
		Lb.setcursor (Cursor.hand);
		
		Pane.getchildren (). Add (lb);
		
		Scene scene=new Scene (pane,300,200);
		
		Stage.setscene (scene);
		Stage.settitle ("Demo");
		Stage.show ();
		
	}


The key part is

Button.setonaction (e->{
			Jfx3 open=new Jfx3 ();
			Try
			{
				Open.start (new Stage ());
				Stage.hide ();
			} 
			catch (Exception E1)
			{
				e1.printstacktrace ();
			}
		});


Call the Start () method of Jfx3.java (to jump to the interface) to achieve the purpose of the Jump interface;

If you need to let the interface of the previous layer not appear, you can invoke the Hide () method to "hide" the previous layer of interface, in the Hide () method document, the explanation is: attempts to hide this Window by setting the visibility to false. It means "trying to hide this window by setting the visibility to false." But the direct "hide" is reasonable I also difficult to judge, welcome everybody to offer the suggestion.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.