Вопрос

I have used shutdown hooks before in java apps however not in java swing. I want to add a shutdown hook to scala swing app. Scala swing has no main method so i have no idea how to implement it I want to run a few methods just before closing so if there other ways beside the shutdown hook please suggest.

Это было полезно?

Решение

Have you looked inside SwingApplication?

https://github.com/scala/scala-swing/blob/v1.0.0-RC2/src/main/scala/scala/swing/SwingApplication.scala#L16

There is a main or a startup to register Runtime.addShutdownHook.

Or there is a shutdown template method if that's all you mean.

Другие советы

Do you mean something similar to this? :

class MyFrame extends Frame {
  peer.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE)

  override def closeOperation() { 
    println("Hello")
    exit(0)
  }
}

Hello will be printed when the Frame is closed.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top