tips350_MouseClicked/scala/src/AppWindow.scala

  1: /*
  2:  * Copyright (c) 2010-2013, KOTSUBU-chan and/or its affiliates.
  3:  * Copyright (c) 1998, Atelier-AYA.
  4:  * All rights reserved.
  5:  */ 
  6: package cherry.pie
  7: 
  8: // ----------------------------------------
  9: // MouseClicked
 10: // ----------------------------------------
 11: import swing._
 12: object AppWindow extends MainFrame {
 13:   val version =          AppWindow
 14:     .getClass.getName+": #1.0.01"
 15:   // ----------------------------------------
 16:   title = "MouseClicked"
 17:   contents = new View(this)
 18:   peer.setLocationRelativeTo(null)
 19: }
 20: 
 21: // ----------------------------------------
 22: class View(frame: Frame) extends Panel {
 23:   preferredSize = new Dimension(260,100)
 24:   new Publisher {
 25:     import swing.event.MouseClicked
 26:     reactions += {
 27:       case MouseClicked(source, point, modifiers, clicks, triggersPopup) =>
 28:         frame.title = point.toString
 29:     }
 30:   }.listenTo(mouse.clicks)
 31: }
 32: 
 33: // EOF

 ↑ TOP

Scala.use(better, Swing); tips#350 MouseClicked

《前の記事|記事一覧|次の記事》
Scala.use(better, Swing)


Tips#350

MouseClicked



地球は、人類にとって唯一の故郷です
それが今、危機に瀕しているのです
これは人道的な問題であり、解決するための選択をするのはあなたです
Al Gore - Wikipedia

《関連記事》

Source code

┃ 仕様


アプリケーションを起動すると、ウインドーが現れます。

ウインドーの上でマウスをクリックすると、その座標がタイトルに表示されます。

┃ 解説

■ イベント処理

 24:   new Publisher {
 25:     import swing.event.MouseClicked
 26:     reactions += {
 27:       case MouseClicked(source, point, modifiers, clicks, triggersPopup) =>
 28:         frame.title = point.toString
 29:     }
 30:   }.listenTo(mouse.clicks)

[27]コンストラクターパターンから、イベント MouseClicked が発生した座標 point を特定できるので、[28]それをタイトルに表示します。

》作業中です《

 ↑ TOP

Created: 2006/04/03|Last updated: 2013/07/17 08:34:14