我能够显示弹出窗口,但是在关闭弹出窗口后它不会替换另一个弹出窗口。关闭弹出窗口后,这个位置将被其前一个弹出替换。我可以关闭保留弹出窗口。这里是我的代码和图片。
我的通知方法在新消息到来时调用。 请帮我解决.my全局变量
private int n = 0;
public void notification(final JSONObject data,final String ip)抛出JSONException {
final Stage stage_notification = new Stage();
stage_notification.initStyle(StageStyle.UNDECORATED);
stage_notification.setWidth(250);
stage_notification.setHeight(70);
Dimension scrnSize = Toolkit.getDefaultToolkit().getScreenSize();
java.awt.Rectangle winSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
int y = (int) (scrnSize.height - (scrnSize.height - winSize.height) - (stage_notification.getHeight() * (n + 1))); //increase popup one by one by adding 1
int x = (int) ((scrnSize.width - stage_notification.getWidth()));
stage_notification.setX(x);
stage_notification.setY(y);
n++;
view_close.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
t.consume();
stage_notification.close();
n--;
}
});
final Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(3),
new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
stage_notification.close();
n--;
}
}));
timeline.play();
}
![enter code here][1]