首页 新闻 搜索 专区 学院

求大神解决一下点击确定按钮要如何才能显示出123,而非null

0
[已解决问题] 解决于 2017-11-26 15:54
import javafx.application.Application;
import javafx.stage.Stage;

public class test extends Application{
    public static void main(String[] args){
        launch();
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        ChangePwController cpc = new ChangePwController();
        cpc.SetStage("123");
        
    }
}

import java.io.IOException;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.PasswordField;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 *
 * @author bird
 */
public class ChangePwController{
    @FXML PasswordField password1;
    @FXML PasswordField password2;
    @FXML Text actiontarget;
    
     String number;
    
    public void SetStage(String number){
        this.number = number;
        Stage primaryStage = new Stage();
        Parent root;
        try {
            root = FXMLLoader.load(getClass().getResource("ChangePwPage.fxml"));
            primaryStage.setTitle("修改密码");
            primaryStage.setScene(new Scene(root, 300, 275));
            primaryStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
        
    }
    
    @FXML protected void ChangePwAction(ActionEvent event){
        System.out.println(number);
    }

}
<?xml version="1.0" encoding="UTF-8"?>

<!--
 * Copyright (c) 2011, 2014 Oracle and/or its affiliates.
 * All rights reserved. Use is subject to license terms.
 *
 * This file is available and licensed under the following license:
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  - Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  - Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the distribution.
 *  - Neither the name of Oracle Corporation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<?import java.lang.*?>
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<GridPane alignment="center" hgap="10" styleClass="root" vgap="10" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.ChangePwController">
  <padding><Insets bottom="10" left="25" right="25" top="25" /></padding>
   <children>
     
     <Text id="welcome-text" text="密码修改" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="0">
         <font>
            <Font size="16.0" />
         </font></Text>
     
     <Label text="新密码:" GridPane.columnIndex="0" GridPane.rowIndex="1" />
     
     <Label text="密码确认:" GridPane.columnIndex="0" GridPane.rowIndex="2" />
     
     <PasswordField fx:id="password1" GridPane.columnIndex="1" GridPane.rowIndex="2" />
     
     <HBox alignment="bottom_right" spacing="10" GridPane.columnIndex="1" GridPane.rowIndex="4">
        <children>
            <Button onAction="#ChangePwAction" text="确定" />
        </children>
     </HBox>
     
     <Text fx:id="actiontarget" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="RIGHT" GridPane.rowIndex="6" />
      <PasswordField fx:id="password2" GridPane.columnIndex="1" GridPane.rowIndex="1" />
      <Text fx:id="number" disable="true" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" visible="true" />
   </children>
  
  <stylesheets>
    <URL value="@ChangePw.css" />
  </stylesheets>
   <columnConstraints>
      <ColumnConstraints />
      <ColumnConstraints />
   </columnConstraints>
   <rowConstraints>
      <RowConstraints />
      <RowConstraints />
      <RowConstraints />
      <RowConstraints />
      <RowConstraints />
      <RowConstraints />
      <RowConstraints />
   </rowConstraints>
  
</GridPane>
霸气的小鸟的主页 霸气的小鸟 | 菜鸟二级 | 园豆:204
提问于:2017-11-25 21:28
< >
分享
最佳答案
0
  public void SetStage(String number){
//          this.number = number;
          Stage primaryStage = new Stage();
          Parent root;
          try {
//              root = FXMLLoader.load(getClass().getResource("ChangePwPage.fxml"));
            FXMLLoader loader = new FXMLLoader( getClass().getResource("ChangePwPage.fxml"));
            root=   loader.load(); 
            ChangePwController control=loader.getController();
            control.number=number;
            primaryStage.setTitle("修改密码");
              primaryStage.setScene(new Scene(root, 300, 275));
              primaryStage.show();
          } catch (IOException e) {
              e.printStackTrace();
          }
          
      }
奖励园豆:5
TCG2008 | 小虾三级 |园豆:1150 | 2017-11-26 14:54

谢谢大佬 

霸气的小鸟 | 园豆:204 (菜鸟二级) | 2017-11-26 15:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册