「javafx跳转」javafx跳转窗口

博主:adminadmin 2022-11-27 03:28:08 184

今天给各位分享javafx跳转的知识,其中也会对javafx跳转窗口进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

javafx实现图书馆界面跳转,要求可以实现借书,还书,查询图书等功能,同时要求登录进入图书馆界面

需要该项目代码的同学可以在我头像简介中找到你需要的东西,发你一份

如何在eclipse中安装java fx

第一步 下载

Download the latest release of the Eclipse 4.3 SDK or of the Eclipse 3.8 SDK fromdownload.eclipse.org

单击Eclipse 4.3 SDK超链接跳转到下载页面

页面中会显示下载项

Latest Downloads

Build Name Build Status Build Date

4.3.2 (3 of 3 platforms) Fri, 21 Feb 2014 -- 17:00 (-0500)

4.4M5 (3 of 3 platforms) Thu, 23 Jan 2014 -- 16:00 (-0500)

I20140306-1200 (2 of 3 platforms) Thu, 6 Mar 2014 -- 12:00 (-0500)

4.3.2RC4a (3 of 3 platforms) Fri, 21 Feb 2014 -- 17:00 (-0500)

N20140301-1500 (2 of 3 platforms) Sat, 1 Mar 2014 -- 15:00 (-0500)

这里选择目前最新的4.3.2

说明中第二步是从Latest Released(最新发布)中下载

但我看了下两个是一样的都是sdk

这里点击4.3.2跳转到下载地址页面

在页面中可以看到这一段

Download now: Eclipse SDK

点击Eclipse SDK

跳转到下载地址列表

页面上显示了很多地址

Eclipse SDK

Status Platform Download Size File Checksum

Windows (Supported Versions) (http) 191 MB eclipse-SDK-4.3.2-win32.zip (md5) (sha1)

Windows (x86_64) (Supported Versions) (http) 191 MB eclipse-SDK-4.3.2-win32-x86_64.zip (md5) (sha1)

Linux (x86/GTK 2) (Supported Versions) (http) 190 MB eclipse-SDK-4.3.2-linux-gtk.tar.gz (md5) (sha1)

Linux (x86_64/GTK 2) (Supported Versions) (http) 190 MB eclipse-SDK-4.3.2-linux-gtk-x86_64.tar.gz (md5) (sha1)

Linux (PPC/GTK 2) (Supported Versions) (http) 188 MB eclipse-SDK-4.3.2-linux-gtk-ppc.tar.gz (md5) (sha1)

Linux (PPC64/GTK 2) (Supported Versions) (http) 188 MB eclipse-SDK-4.3.2-linux-gtk-ppc64.tar.gz (md5) (sha1)

Linux (s390x/GTK 2) (Supported Versions) (http) 188 MB eclipse-SDK-4.3.2-linux-gtk-s390x.tar.gz (md5) (sha1)

Linux (s390/GTK 2) (Supported Versions) (http) 188 MB eclipse-SDK-4.3.2-linux-gtk-s390.tar.gz (md5) (sha1)

Solaris 10 (SPARC/GTK 2) (http) 188 MB eclipse-SDK-4.3.2-solaris-gtk.zip (md5) (sha1)

Solaris 10 (x86/GTK 2) (http) 188 MB eclipse-SDK-4.3.2-solaris-gtk-x86.zip (md5) (sha1)

HP-UX (ia64/GTK 2) (http) 188 MB eclipse-SDK-4.3.2-hpux-gtk-ia64.zip (md5) (sha1)

AIX (PPC/GTK 2) (http) 189 MB eclipse-SDK-4.3.2-aix-gtk-ppc.zip (md5) (sha1)

AIX (PPC64/GTK 2) (http) 189 MB eclipse-SDK-4.3.2-aix-gtk-ppc64.zip (md5) (sha1)

Mac OSX (Mac/Cocoa) (Supported Versions) (http) 188 MB eclipse-SDK-4.3.2-macosx-cocoa.tar.gz (md5) (sha1)

Mac OSX (Mac/Cocoa/x86_64) (Supported Versions) (http) 190 MB eclipse-SDK-4.3.2-macosx-cocoa-x86_64.tar.gz (md5) (sha1)

注意!第一次看会不知道哪里是下载

点Windows (Supported Versions) 会直接跳转到说明页面上去

搞得人晕头转向

这里正确的是点击(http)

然后就开始下载了

第二步 安装

到这里你就成功一半了。

然而容易出现错误的地方也在这里。

如果只添加了插件安装地址的话安装到一半就会报错

首先打开eclipse SDK

依照安装的一般方法在Help中打开Install New Software

重点!!!

在这个地方首先添加Xtext的升级更新地址

Name随便填

添加了之后才能添加

选择版本

这里我们是kepler版本所以选择e(fx)clipse - IDE - kepler

安装就会正常结束了

完成后会要求重启eclipse

重启就完成了安装

第三步 新建一个工程

到这里新建工程就很简单了

和新建普通Java Project一样

在eclipse的package explorer中右键New → Other...

就可以看到JavaFX的文件夹

在里面选择JavaFX Project

系统就会默认新建一个JavaFX模板

在有Main方法文件上run一下

默认就是一个空白窗口弹出

到此说明全部结束

当然我个人想要把applet嵌入到网页里的话

还可以邮件添加JavaFX Html Template(虽然还没试过)

至于我为什么要选择JavaFX

Oracle网站里有关于JavaFX的sample

下面有两个范例一个是用HTML嵌入插件的一个是可以用swing做的

这里打开Ensemble你会发现sample本身都是用jfx来做的

炒鸡赞

Try Ensemble running inside browser as an applet

Try Ensemble running as a Java Web Start application.

Try Swing chart running inside browser as an applet

Try Swing chart running as a Java Web Start application.

装完jfx的eclipse里也有sample一个

看上去非常好支持原生Java还支持3D

网上也查了速度优化也不错那个赞……

总之自己试试就知道了

番外 关于applet插件

因为我原来安装过Java所以电脑上有

运行J2SE程序也只用在环境里配置一下就好了

但问题是网页上的applet怎么都提示要安装

网上查了一下似乎只能用exe安装包安装jre

据说是需要写注册表还要安装浏览器插件

想了一下原理也确实是这样

感觉这一点oracle要是能改进就好了

番外 关于完整版e(fx)clipse下载

有人说e(fx)clipse有完整版的为什么还要手动去装插件?

答曰那个完整版的eclipse里面集成了几乎所有的工具

而这些工具有八成以上我几乎都不会用到

我为啥要装上去?

当然你选择装这种傻瓜版的之后再把多的插件卸掉也行

不过会不会遇到其它麻烦就不得而知了

番外 关于eclipse插件没装成功时

javafx怎么实现页面的跳转

1. 后台

public class Check {

public static boolean checkreturn(String account,String password){

boolean checkbool = false;

if("account".equals(account)"password".equals(password)){

checkbool = true;

}

return checkbool;

}

}

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.Initializable;

import javafx.scene.control.PasswordField;

import javafx.scene.control.TextField;

public class LoginController implements Initializable {

@FXML private TextField account;

@FXML private PasswordField password;

private FXMLTest application;

public void setApp(FXMLTest application){

this.application = application;

}

@FXML

public void LOGIN_M(ActionEvent event) {

application.userlogin(account.getText(), password.getText());

}

@FXML

private void CLEAR_M(ActionEvent event) {

account.setText(null);

password.setText(null);

}

@Override

public void initialize(URL url, ResourceBundle rb) {

// TODO

}

}

import java.net.URL;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.Initializable;

public class MainController implements Initializable{

private FXMLTest application;

public void setApp(FXMLTest application){

this.application = application;

}

@FXML

private void OUT_M(ActionEvent event) {

application.useroutmain();

}

@Override

public void initialize(URL url, ResourceBundle rb) {

}

}

import check.Check;

import java.io.InputStream;

import java.util.logging.Level;

import java.util.logging.Logger;

import javafx.application.Application;

import javafx.fxml.FXMLLoader;

import javafx.fxml.Initializable;

import javafx.fxml.JavaFXBuilderFactory;

import javafx.scene.Scene;

import javafx.scene.layout.AnchorPane;

import javafx.stage.Stage;

public class FXMLTest extends Application {

private Stage stage;

private final double MINIMUM_WINDOW_WIDTH = 400.0;

private final double MINIMUM_WINDOW_HEIGHT = 250.0;

@Override

public void start(Stage primaryStage) throws Exception {

stage = primaryStage;

stage.setTitle("FXML Login Sample");

stage.setMinWidth(MINIMUM_WINDOW_WIDTH);

stage.setMinHeight(MINIMUM_WINDOW_HEIGHT);

gotologin();

stage.show();

}

public void gotologin(){

try {

LoginController login = (LoginController) replaceSceneContent("FXML_LOGIN.fxml");

login.setApp(this);

} catch (Exception ex) {

Logger.getLogger(FXMLTest.class.getName()).log(Level.SEVERE, null, ex);

}

}

public void gotomain(){

try {

MainController main = (MainController) replaceSceneContent("FXML_MAIN.fxml");

main.setApp(this);

} catch (Exception ex) {

Logger.getLogger(FXMLTest.class.getName()).log(Level.SEVERE, null, ex);

}

}

public void userlogin(String account,String password){

if(Check.checkreturn(account,password)){

gotomain();

}

}

public void useroutmain(){

gotologin();

}

private Initializable replaceSceneContent(String fxml) throws Exception {

FXMLLoader loader = new FXMLLoader();

InputStream in = FXMLTest.class.getResourceAsStream(fxml);

loader.setBuilderFactory(new JavaFXBuilderFactory());

loader.setLocation(FXMLTest.class.getResource(fxml));

AnchorPane page;

try {

page = (AnchorPane) loader.load(in);

} finally {

in.close();

}

Scene scene = new Scene(page, 800, 600);

stage.setScene(scene);

stage.sizeToScene();

return (Initializable) loader.getController();

}

public static void main(String[] args) {

launch(args);

}

}

2. xml配置

?xml version="1.0" encoding="UTF-8"?

?import java.lang.*?

?import java.util.*?

?import javafx.geometry.*?

?import javafx.scene.control.*?

?import javafx.scene.effect.*?

?import javafx.scene.layout.*?

?import javafx.scene.paint.*?

?import javafx.scene.text.*?

AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="400.0"

xmlns:fx="" fx:controller="fxmltest.LoginController"

children

VBox layoutX="3.0" layoutY="0.0" prefHeight="250.0" prefWidth="390.0" spacing="20.0"

children

HBox minHeight="37.0" prefHeight="37.0" prefWidth="411.0"

children

Label text="登陆界面"

effect

DropShadow height="7.845238095238096" radius="4.1815476190476195" width="10.880952380952381" /

/effect

font

Font name="System Bold" size="30.0" /

/font

HBox.margin

Insets left="140.0" /

/HBox.margin

/Label

/children

/HBox

GridPane alignment="TOP_RIGHT" prefWidth="380.0"

children

Label alignment="TOP_RIGHT" text="Account" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="0"

effect

DropShadow blurType="TWO_PASS_BOX" height="7.845238095238096" radius="3.675595238095238" width="8.857142857142858" /

/effect

font

Font size="25.0" fx:id="x1" /

/font

GridPane.margin

Insets right="8.0" fx:id="x2" /

/GridPane.margin

/Label

Label font="$x1" text="password" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.margin="$x2" GridPane.rowIndex="1"

effect

DropShadow blurType="TWO_PASS_BOX" height="7.845238095238094" radius="3.6755952380952372" width="8.857142857142854" /

/effect

/Label

TextField fx:id="account" prefHeight="26.0" prefWidth="268.0" promptText="please input your account" GridPane.columnIndex="1" GridPane.rowIndex="0" /

PasswordField fx:id="password" prefWidth="223.0" promptText="please input your password" GridPane.columnIndex="1" GridPane.rowIndex="1" /

Button id="btn_login" mnemonicParsing="false" onAction="#LOGIN_M" prefWidth="80.0" text="登陆" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="2"

effect

DropShadow /

/effect

GridPane.margin

Insets top="15.0" /

/GridPane.margin

/Button

Button id="btn_clear" mnemonicParsing="false" onAction="#CLEAR_M" prefWidth="80.0" text="清除" GridPane.columnIndex="1" GridPane.rowIndex="2"

effect

DropShadow /

/effect

GridPane.margin

Insets left="80.0" top="15.0" /

/GridPane.margin

/Button

/children

columnConstraints

ColumnConstraints hgrow="SOMETIMES" maxWidth="205.0" minWidth="10.0" prefWidth="147.0" /

ColumnConstraints hgrow="SOMETIMES" maxWidth="318.0" minWidth="10.0" prefWidth="243.0" /

/columnConstraints

rowConstraints

RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /

RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /

RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /

/rowConstraints

/GridPane

/children

padding

Insets top="30.0" /

/padding

/VBox

/children

/AnchorPane

?xml version="1.0" encoding="UTF-8"?

?import java.lang.*?

?import java.util.*?

?import javafx.scene.control.*?

?import javafx.scene.layout.*?

?import javafx.scene.paint.*?

?import javafx.scene.text.*?

AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"

xmlns:fx="" fx:controller="fxmltest.MainController"

children

Hyperlink layoutX="86.0" layoutY="111.0" text="退出登录!" onAction="#OUT_M"

font

Font size="45.0" /

/font

/Hyperlink

/children

/AnchorPane

javaFX如何用Button实现跳转到一个已创建的fxml界面

可以在“按钮点击事件”中写上读取fmxl为节点对象

Parent root = FXMLLoader.load(getClass().getResource("fxml_example.fxml"));

然后把父节点放入某个new Scene(root,320,200);

然后在显示在所用的舞台stage上。

javafx pagination分页 怎样跳转

Pagination的创建方式有两种:

第一种是直接进行Pagination的初始化,然后进行相关参数的设置。

第二种是使用PaginationBuilder使用建造者模式进行Pagination的构建。

如何在java程序中,当点击一个按钮后,关闭当前窗口,开启一个新的窗口。

首先分析需要的GUI技术

java中一般使用swing 和awt技术来实现图形界面,Swing组件较多,功能比较强大,所以这里使用Swing组件来实现。窗口使用(JFrame),按钮使用(JButton)。

设想一个符合题目需求的场景

两个窗口关联并且跳转,最常见的场景就是登陆了。

登陆窗口,输入用户名和密码,如果成功就跳转到主窗口

核心逻辑,跳转窗口的关键代码

一般可以隐藏本窗口(setVisible(false);),显示新窗口来实现窗口的跳转。

但是隐藏窗口,会在后面浪费系统资源。

如果不再使用该窗口,应该彻底销毁(dispose();),释放系统资源

代码和注释

LoginFrame 类

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

//LoginFrame 登陆窗口  功能 实现用户登陆 ,如果成功就跳转

//LoginFrame 继承于窗口类, 并实现ActionListener接口

public class LoginFrame extends JFrame implements ActionListener {

// 申明需要的组件

JButton jb1, jb2;//按钮

JTextField jtf1;//文本框

JPasswordField jpf1;//密码框

public LoginFrame() {

// 窗口属性的设置

setTitle("登陆窗");// 窗口标题

setSize(300, 180);// 窗口大小

setLocationRelativeTo(null);// 窗口居中

setDefaultCloseOperation(EXIT_ON_CLOSE);// 关闭窗口则退出虚拟机

setLayout(new FlowLayout());// 设置布局流式布局

JPanel jp = new JPanel(new GridLayout(4, 1));// 设置面板为表格布局4行1列

// 第一行

JPanel jp1 = new JPanel();

JLabel jl1 = new JLabel("账号 ");

jtf1 = new JTextField(12);

jp1.add(jl1);

jp1.add(jtf1);

jp.add(jp1);

// 第二行

JPanel jp2 = new JPanel();

JLabel jl2 = new JLabel("密码 ");

jpf1 = new JPasswordField(12);

jp2.add(jl2);

jp2.add(jpf1);

jp.add(jp2);

// 第三行

JPanel jp3 = new JPanel();

jb1 = new JButton("登陆");

jb1.addActionListener(this);// 添加动作响应器

jb2 = new JButton("重置");

jb2.addActionListener(this);// 添加动作响应器

jp3.add(jb1);

jp3.add(jb2);

jp.add(jp3);

// 第四行

JPanel jp4 = new JPanel();

JLabel jl3 = new JLabel("提示: 账号 admin 密码 123");

jl3.setForeground(Color.DARK_GRAY);

jp4.add(jl3);

jp.add(jp4);

add(jp);

}

// 动作响应

public void actionPerformed(ActionEvent e) {

String cmd = e.getActionCommand();// 根据动作命令,来进行分别处理

if (cmd.equals("登陆")) {

String id = jtf1.getText();// 取得用户名

String key = new String(jpf1.getPassword());// 取得密码

if (id.equals("admin")  key.equals("123")) {// 判断是否登录成功

// 如果登录成功

setVisible(false);// 本窗口隐藏,

new MainFrame(id).setVisible(true);// 新窗口显示

dispose();//本窗口销毁,释放内存资源

} else {

//如果登录失败  弹出提示

JOptionPane.showMessageDialog(this, "用户名或者密码错误.", "通知", JOptionPane.ERROR_MESSAGE);

clearText();//清空文本框 密码框的输入

}

} else if (cmd.equals("重置")) {

clearText();

}

}

private void clearText() {//清空文本框, 密码框的输入

jtf1.setText("");

jpf1.setText("");

}

//main方法, 程序的入口

public static void main(String[] args) {

new LoginFrame().setVisible(true);//创建登录窗口,并可见

}

}

MainFrame类

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class MainFrame extends JFrame {

public MainFrame(String name) {

setTitle("主窗口");//标题

setSize(300, 260);//大小

setLocationRelativeTo(null);//居中

setDefaultCloseOperation(EXIT_ON_CLOSE);

JPanel jp = new JPanel();

JLabel jl1 = new JLabel("欢迎");

JLabel jl2 = new JLabel(name);

jl2.setForeground(Color.BLUE);//设置文本颜色

JLabel jl3 = new JLabel("使用系统.");

jp.add(jl1);

jp.add(jl2);

jp.add(jl3);

add(jp, BorderLayout.NORTH);

JTextArea jta = new JTextArea();

jta.setLineWrap(true);

jta.append("消息提示");

jta.append(" 消息!通知~!");

JScrollPane jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

add(jsp);

JPanel jp2 = new JPanel();

JButton jb = new JButton("退出");

jb.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

System.exit(0);//退出

}

});

jp2.add(jb);

add(jp2,BorderLayout.SOUTH);

}

}

运行效果图

javafx跳转的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于javafx跳转窗口、javafx跳转的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-27,除非注明,否则均为首码项目网原创文章,转载请注明出处。