Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

Java Swing Program to JavaFx

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...