JavaFx實(shí)現(xiàn)登錄成功跳轉(zhuǎn)到程序主頁面
本文實(shí)例為大家分享了JavaFx實(shí)現(xiàn)登錄成功跳轉(zhuǎn)到程序主頁面的具體代碼,供大家參考,具體內(nèi)容如下
1、需求
登錄頁面在輸入賬號(hào)密碼之后,驗(yàn)證賬號(hào)密碼時(shí)候正確,正確就跳轉(zhuǎn)到應(yīng)用程序的首頁。
文筆不行,可能沒怎么寫清楚,歡迎在下面討論
效果如下圖:
2、實(shí)現(xiàn)
1)、LoginApplication為啟動(dòng)類,啟動(dòng)之后進(jìn)入到登錄頁面
public class LoginApplication extends Application { ? ? @Override ? ? public void start(Stage stage) throws IOException { ? ? ? ? AnchorPane Login = FXMLLoader.load(getClass().getClassLoader().getResource("FXML/Login/Login.fxml")); ? ? ? ? Scene login = new Scene(Login); ? ? ? ? stage.setTitle("登錄");//設(shè)置標(biāo)題 ? ? ? ? stage.setScene(login); ? ? ? ? stage.show(); ? ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? launch(args); ? ? } }
2)、LoginController 類進(jìn)行判斷密碼的正確性,當(dāng)密碼正確的時(shí)候關(guān)閉登錄窗口,打開主頁面窗口
public class LoginController { ? ? @FXML ? ? private TextField NumberTextField; ? ? @FXML ? ? private TextField PasswordTextField; ? ? @FXML ? ? private Label MessageLabel; ? ? @FXML ? ? private Button LoginButton; ? ? public void loginButtonClick(ActionEvent event) throws IOException { ? ? ? ? String number = NumberTextField.getText(); ? ? ? ? String password = PasswordTextField.getText(); ? ? ? ? if (number != null && !number.equals("") && password != null && !password.equals("")) { ? ? ? ? ? ? boolean login = LoginJudge.Login(number, password); ? ? ? ? ? ? if (login == true){ ? ? ? ? ? ? ? ? MessageLabel.setText("登錄成功"); ? ? ? ? ? ? ? ? Stage primaryStage=(Stage)LoginButton.getScene().getWindow();//將submit(登錄按鈕)與MainApplication類中的primaryStage(新窗口)綁定 并執(zhí)行close() ? ? ? ? ? ? ? ? primaryStage.close();//打開新的窗口 所以要關(guān)閉當(dāng)前的窗口 ? ? ? ? ? ? ? ? MainApplication mainApplication = new MainApplication();//新窗口類 ? ? ? ? ? ? ? ? mainApplication.MainApp();//打開新窗口 ? ? ? ? ? ? }else { ? ? ? ? ? ? ? ? MessageLabel.setText("賬號(hào)或密碼錯(cuò)誤"); ? ? ? ? ? ? } ? ? ? ? }else { ? ? ? ? ? ? MessageLabel.setText("請(qǐng)輸入賬號(hào)或密碼"); ? ? ? ? } ? ? } }
3)、MainApplication為主頁面的類,LoginController調(diào)用這個(gè)類來啟動(dòng)主頁面
public class MainApplication { ? ? public void MainApp() throws IOException { ? ? ? ? AnchorPane root = FXMLLoader.load(getClass().getClassLoader().getResource("FXML/Main.fxml")); ? ? ? ? Scene scene = new Scene(root); ? ? ? ? scene.getStylesheets().add(getClass().getResource("/CSS/MainCss.css").toExternalForm()); ? ? ? ? Stage stage = new Stage(); ? ? ? ? stage.setTitle("技術(shù)支持工作臺(tái)");//設(shè)置標(biāo)題 ? ? ? ? stage.setScene(scene); ? ? ? ? stage.show(); ? ? } }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Spring-AOP自動(dòng)創(chuàng)建代理之BeanNameAutoProxyCreator實(shí)例
這篇文章主要介紹了Spring-AOP自動(dòng)創(chuàng)建代理之BeanNameAutoProxyCreator實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07zuul集成Sentinel,完成對(duì)path映射的限流操作
這篇文章主要介紹了zuul集成Sentinel,完成對(duì)path映射的限流操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06spring boot中的properties參數(shù)配置詳解
這篇文章主要介紹了spring boot中的properties參數(shù)配置,需要的朋友可以參考下2017-09-09java判斷請(qǐng)求是來自PC端還是手機(jī)端小技巧
這篇文章主要為大家介紹了java判斷請(qǐng)求是來自PC端還是手機(jī)端小技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06方法參數(shù)屬性params,@PathVariable和@RequestParam用法及區(qū)別
這篇文章主要介紹了方法參數(shù)屬性params,@PathVariable和@RequestParam用法及區(qū)別說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10Java多例Bean的應(yīng)用場景-easyExcel導(dǎo)入
EasyExcel 是一個(gè)基于 Java 的簡單、省內(nèi)存的讀寫 Excel 的開源項(xiàng)目。這篇文章主要介紹了用easyExcel導(dǎo)入Java Bean的應(yīng)用場景,感興趣的朋友可以參考閱讀2023-04-04springboot如何獲取相對(duì)路徑文件夾下靜態(tài)資源的方法
這篇文章主要介紹了springboot如何獲取相對(duì)路徑文件夾下靜態(tài)資源的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-05-05