// // program to demonstrate something like animation: // "blink" a rectangle off and on // import scala.swing._ import java.awt.Color import java.awt.Graphics2D // variable we can toggle off/on to produce "blink" effect var blinkOn = false; // main panel in the display val blinkPanel = new Panel { override def paint(g : Graphics2D) { g.setPaint(Color.WHITE) g.fillRect(0, 0, size.width, size.height) if (blinkOn) { g.setPaint(Color.BLACK) g.fillRect(size.width/4, size.height/4, size.width/2, size.height/2) } } } // simple menu to allow start/stop val fileMenu = new Menu("Actions") { contents += new MenuItem(Action("Start")( timer.start() )) contents += new MenuItem(Action("Stop")( timer.stop() )) contents += new MenuItem(Action("Exit")( sys.exit(0) )) } // timer to produce "blink" effect val BlinkInterval = 500 // in milliseconds val timer=new javax.swing.Timer(BlinkInterval, Swing.ActionListener(e => { blinkOn = !blinkOn blinkPanel.repaint() } )) // main layout val frame = new MainFrame { title = "Blink" contents = new BorderPanel { layout += (blinkPanel -> BorderPanel.Position.Center) } menuBar = new MenuBar { contents += fileMenu } size = new Dimension(200,200) } // start up frame.visible = true