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...
===========================================================
//--------------------------------------------------------------------------------------------------
// 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();
}
}
}
//--------------------------------------------------------------------------------------------------
//This works. Place in your Controller. Then attach to a button.
public void close(ActionEvent event) throws Exception{
Platform.exit();
}
Praying for the RUclips algorithm :)
Bro, RUclips only notify me of one video, but you upload like 5, im still thinking that is better you upload one daily :c
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.
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
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 🥰
Awesome tutorial! It helped me so much .Thank you Sir!. More power to you SIR!
Bro, you help Ukrainian students! Thank you so much!
Awesome! Thanks so much! I enjoy your tutorials! :)
I can't thank you enough bro your course pretty fantastic.
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
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!!!
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.
Bro, what color scheme are you using? I am using IntelliJ and wondering if there is the same as yours... Thanks!
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 :')
An amazing explanation, thank you!!
Now my poor student work has become a nice and ellegant aplication XD
une video comment installer fontawesome
the video i've been looking for 3 days.... finally.... THANK YOU SO MUCH!
wow last time i was here you had 1k subs o.o :clap: :clap:
Hi there. How to set the button relative positions in anchor pane? I forgot it....
Hey mate thanks you - but can you link your eclipse theme?
I'm glad I subscribed
I love your Java GUI tutorials
Thanks!
Please use only simple notepad and create any program and project without using any any IDE and framework for batter understanding
But most of the time, you're going to use an IDE to code Java.
da best
Please make a instragram or telegram account so we can interact
Please make a unity beginner tutorial!!
That is great!
COOL BRO
you are special
Here to boost algorithm :)
Very cool man thanks
thank u so much Bro Code
pls make lwjgl tutorial
Tyty
Thanks a lot bro❤️
Nice video Bro!!
Great video!
Useful 👌👍
Thx Bro!
nice video!
Thank you
👌👌👌👌👍
👍👍👍