I am trying to implement a automatic logout function in javaFx I have already done this in Java Swing and it working perfecly but there some differences when it comes to JavaFx.
The code in Swing
public void logout(){
this.setVisible(false)
new Frame1().setVisible(true);
}
public void session(){
stopTimer();
t = new Timer(10000, new ActionListner(){
@Override
public void actionPerformed(ActionEvent e){
logout();
}
});
t.start();
}
public void stopTimer(){
if(t!= null){
t.stop();
}
public void inter(){
session();
}
private void formMouseMoved(java.awt.event.MouseEvent evet){
inter();
}
There is no ActionLister in javaFx that function (session) is where I'm Stuck
javaFx Code
Duration second = Duration.seconds(5);
Duration empty = Duration.seconds(0);
Duration s;
public void extend(){
if(second.toSeconds() != 60){
s = second.add(second);
}else {
s = second.add(empty);
}
}
public void sessionStart(){
extend();
PauseTransition pause = new PauseTransition(s);
pause.stop();
pause.setOnFinished(event ->
logout(event));
pause.play();
}
I tried this code. I called the sessionStart()
as the onMouseMoved
in the borderPane
if i move the mouse 10 times the logout window will appear 10 times
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…