Skip to content

Instantly share code, notes, and snippets.

@NomadBlacky
Created March 7, 2019 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NomadBlacky/a70d76f5d699994da83c92775935f3f6 to your computer and use it in GitHub Desktop.
Save NomadBlacky/a70d76f5d699994da83c92775935f3f6 to your computer and use it in GitHub Desktop.
何度閉じてもダイアログが出てくるScalaスクリプト
import java.awt._, event._
import javax.swing._
import scala.util.Random
val (screenCenterW, screenCenterH) = {
val ss = Toolkit.getDefaultToolkit().getScreenSize
(ss.getWidth.toInt / 2, ss.getHeight.toInt / 2)
}
val label = new JLabel("何回閉じても無駄ですよ~ww")
def randomLocation(): (Int, Int) =
(screenCenterW + Random.nextInt(200) - 200, screenCenterH + Random.nextInt(200) - 200)
def newDialog(): Unit = {
val dialog = new JDialog()
dialog.setSize(300, 200)
val (x, y) = randomLocation()
dialog.setLocation(x, y)
dialog.add(label)
dialog.setVisible(true)
dialog.addWindowListener(new WindowAdapter {
override def windowClosing(e: WindowEvent): Unit = {
newDialog()
}
})
}
newDialog()
@NomadBlacky
Copy link
Author

dialog.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment