JavaFX logout/exit button 🚪

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024
  • Javafx close exit logout tutorial example explained
    #javafx #close #exit
    music credits 🎼 :
    ===========================================================
    Up In My Jam (All Of A Sudden) by - Kubbi / kubbi
    Creative Commons - Attribution-ShareAlike 3.0 Unported- CC BY-SA 3.0
    Free Download / Stream: bit.ly/2JnDfCE
    Music promoted by Audio Library • Up In My Jam (All Of A...
    ===========================================================

Комментарии • 44

  • @BroCodez
    @BroCodez  3 года назад +18

    //--------------------------------------------------------------------------------------------------
    // JavaFX Logout button
    // -------------------------------------------------------------------------------------------------
    package application;

    import javafx.application.Application;
    import javafx.fxml.FXMLLoader;
    import javafx.stage.Stage;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.scene.control.Alert;
    import javafx.scene.control.ButtonType;
    import javafx.scene.control.Alert.AlertType;
    public class Main extends Application {

    @Override
    public void start(Stage stage) {
    try {
    Parent root = FXMLLoader.load(getClass().getResource("Scene.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();

    stage.setOnCloseRequest(event -> {
    event.consume();
    logout(stage);
    });

    } catch(Exception e) {
    e.printStackTrace();
    }
    }

    public void logout(Stage stage){

    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Logout");
    alert.setHeaderText("You're about to logout!");
    alert.setContentText("Do you want to save before exiting?");

    if (alert.showAndWait().get() == ButtonType.OK){
    System.out.println("You successfully logged out");
    stage.close();
    }
    }
    public static void main(String[] args) {
    launch(args);
    }
    }
    //-----------------------------------------Scene.fxml------------------------------------------



    //--------------------------------------Controller.java-----------------------------------------
    package application;
    import javafx.event.ActionEvent;
    import javafx.fxml.FXML;
    import javafx.scene.control.Alert;
    import javafx.scene.control.Alert.AlertType;
    import javafx.scene.control.Button;
    import javafx.scene.control.ButtonType;
    import javafx.scene.layout.AnchorPane;
    import javafx.stage.Stage;
    public class Controller {

    @FXML
    private Button logoutButton;
    @FXML
    private AnchorPane scenePane;

    Stage stage;

    public void logout(ActionEvent event) {

    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Logout");
    alert.setHeaderText("You're about to logout!");
    alert.setContentText("Do you want to save before exiting?: ");

    if(alert.showAndWait().get() == ButtonType.OK){
    stage = (Stage) scenePane.getScene().getWindow();
    System.out.println("You successfully logged out!");
    stage.close();
    }

    }
    }
    //--------------------------------------------------------------------------------------------------

  • @XBMAN
    @XBMAN Год назад +3

    //This works. Place in your Controller. Then attach to a button.
    public void close(ActionEvent event) throws Exception{
    Platform.exit();
    }

  • @jegor06
    @jegor06 3 года назад +4

    Praying for the RUclips algorithm :)

  • @Verzach3
    @Verzach3 3 года назад +1

    Bro, RUclips only notify me of one video, but you upload like 5, im still thinking that is better you upload one daily :c

  • @parsa8533
    @parsa8533 2 года назад +2

    Appreciate the tutorial Bro! may I ask where you learnt this stuff (eg. what documentation, reference you use)? I followed along but I need to start being more independent with javafx.

    • @sravanis1948
      @sravanis1948 2 года назад

      Same here. Are you familiar with JavaFx? I am stuck with some scenario that i am implementing now, would you be able to help? I am pulling my hair as i am half way through it getting conflicts now. Thank you very much

  • @lequangnghi194
    @lequangnghi194 Год назад +1

    Hi Bro, I'm kinda confused with the "@FXML"
    Can I ask how it works and when to use it?
    I love your channel btw 🥰

  • @sidrasoniaaziz9858
    @sidrasoniaaziz9858 3 года назад +2

    Awesome tutorial! It helped me so much .Thank you Sir!. More power to you SIR!

  • @artemkasper8209
    @artemkasper8209 3 года назад +1

    Bro, you help Ukrainian students! Thank you so much!

  • @Dswilsonangel
    @Dswilsonangel 2 года назад +1

    Awesome! Thanks so much! I enjoy your tutorials! :)

  • @alipro1284
    @alipro1284 Год назад +1

    I can't thank you enough bro your course pretty fantastic.

  • @rubensalves8267
    @rubensalves8267 Год назад

    Brooo, thanks for the classes!! I'd like to comment here about an issue that I had. I don't know why but I discovered that the Controller needs to contain the fxml's file name in its name. I was almost got crazy trying to discover why scenebuilder couldn't find my controller classes that I named all way😅. So I hope this information helps someone. b:y)e

  • @christinley5213
    @christinley5213 3 года назад

    Man dude..u put in wrk..just watched u drop like 3 vids a day lol..I'm still on new java full course lol. Thank you for this dude..there's like no java 15 books!!!

  • @sravanis1948
    @sravanis1948 2 года назад

    Hi, Can you help me with this scenario ? If the application is idle, logout the user. I am able to achieve this using PauseTransition on a single scene, but i get multiple dialogues on every scene? I created a transition on start method and also calling on each reset scenes of menu Items that i have on the application. I am showing up a dialogue on finish transition.

  • @gedasred1
    @gedasred1 3 года назад

    Bro, what color scheme are you using? I am using IntelliJ and wondering if there is the same as yours... Thanks!

  • @tuV13ja
    @tuV13ja 3 года назад

    Can you make a video about good practices/design patterns for data validation from UI and comunication with business logic ???? I've never seen a video about it, so you can be the chosen one for this job :')

  • @RolandBlaucel
    @RolandBlaucel 2 года назад

    An amazing explanation, thank you!!
    Now my poor student work has become a nice and ellegant aplication XD

  • @abdelazizmfendounmouncharo2572
    @abdelazizmfendounmouncharo2572 7 месяцев назад

    une video comment installer fontawesome

  • @reyc9071
    @reyc9071 3 года назад

    the video i've been looking for 3 days.... finally.... THANK YOU SO MUCH!

  • @bluenone
    @bluenone 3 года назад

    wow last time i was here you had 1k subs o.o :clap: :clap:

  • @jianhe
    @jianhe 3 года назад

    Hi there. How to set the button relative positions in anchor pane? I forgot it....

  • @silvergodanalyser7762
    @silvergodanalyser7762 3 года назад

    Hey mate thanks you - but can you link your eclipse theme?

  • @gentworm2377
    @gentworm2377 3 года назад

    I'm glad I subscribed
    I love your Java GUI tutorials
    Thanks!

  • @bgsound7
    @bgsound7 3 года назад

    Please use only simple notepad and create any program and project without using any any IDE and framework for batter understanding

    • @amsyarzero
      @amsyarzero 2 года назад

      But most of the time, you're going to use an IDE to code Java.

  • @chemso_1
    @chemso_1 5 месяцев назад

    da best

  • @wolfie1675
    @wolfie1675 3 года назад

    Please make a instragram or telegram account so we can interact

  • @ИльяТимофеев-я8о
    @ИльяТимофеев-я8о 3 года назад

    Please make a unity beginner tutorial!!

  • @nicobonder
    @nicobonder 6 месяцев назад

    That is great!

  • @ctluwua7695
    @ctluwua7695 3 года назад

    COOL BRO
    you are special

  • @MichaelHV
    @MichaelHV 3 года назад

    Here to boost algorithm :)

  • @BRANDONESNEIDERACEVEDOCASTANED

    Very cool man thanks

  • @vishwak1812
    @vishwak1812 3 года назад

    thank u so much Bro Code

  • @MetinCloup
    @MetinCloup 3 года назад

    pls make lwjgl tutorial

  • @Arxa93
    @Arxa93 2 года назад

    Tyty

  • @malakjaber1692
    @malakjaber1692 2 года назад

    Thanks a lot bro❤️

  • @vietismee4884
    @vietismee4884 2 года назад

    Nice video Bro!!

  • @wolanus
    @wolanus 3 года назад

    Great video!

  • @ashkanshakiba9579
    @ashkanshakiba9579 3 года назад

    Useful 👌👍

  • @pawe7420
    @pawe7420 Год назад

    Thx Bro!

  • @juanxpeke
    @juanxpeke 2 года назад

    nice video!

  • @adroaldoferreira978
    @adroaldoferreira978 3 года назад

    Thank you

  • @fabianrr
    @fabianrr 3 года назад

    👌👌👌👌👍

  • @vitalina6456
    @vitalina6456 2 года назад

    👍👍👍