scala/ScalaBook/chapter-06/197ma.scala
import scala.swing._
import scala.swing.event._
object hello extends SimpleGUIApplication {//1
def top = new MainFrame {//2
//
title = "Greetings"
preferredSize = (800,200)
val label = new Label {//3
text = "Hello World!"
font = new java.awt.Font("Verdana", java.awt.Font.BOLD,22)
}//3
val help_button1 = new Button {//4
text = "Help1"
font = new java.awt.Font("Verdana",java.awt.Font.PLAIN, 14)
}//4
val help_button2 = new Button {//4
text = "Help2"
font = new java.awt.Font("Verdana",java.awt.Font.PLAIN, 14)
}//4
val close_button = new Button {//5
text = "Close Window"
font = new java.awt.Font("Verdana",java.awt.Font.PLAIN, 14)
}//5
//
///////////////////////}
contents = new GridBagPanel {//6
//
var c = new Constraints
c.gridwidth = java.awt.GridBagConstraints.REMAINDER
add(label, c)
add(Swing.VStrut(20), c)
//
c.gridwidth = java.awt.GridBagConstraints.RELATIVE
add(help_button1, c)
//add(Swing.HStrut(1), c)
add(help_button2, c)
c.gridwidth = java.awt.GridBagConstraints.REMAINDER
add(close_button, c)
//background = java.awt.Color.yellow
//border = Swing.EmptyBorder(15, 15, 15, 15)
}//6
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
listenTo(help_button1)
reactions += {//7
case ButtonClicked(b1) => if(b1.equals(help_button1)) new Frame {//8
title = "Help Window"
visible = true
val close_button2 = new Button { text = "Close" }
val help_text = new TextArea {//9
editable = false
text = "Click the «Κλείσιμο» button to . . .1"
}
contents = new GridBagPanel {
var c = new Constraints
c.gridwidth = java.awt.GridBagConstraints.REMAINDER
add(help_text, c)
add(Swing.VStrut(20), c)
add(close_button2,c)
background = java.awt.Color.yellow
border = Swing.EmptyBorder(15, 15, 15, 15)
}
listenTo(close_button2)
reactions += {//11
case ButtonClicked(b3) => dispose()
}
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
listenTo(help_button2)
reactions += {//7
case ButtonClicked(b1) => if(b1.equals(help_button2)) new Frame {//8
title = "Help Window"
visible = true
val close_button3 = new Button { text = "Close" }
val help_text2 = new TextArea {//9
editable = false
text = "Click the «Κλείσιμο» button to . . .2"
}//9
contents = new GridBagPanel {//10
//
var c = new Constraints
c.gridwidth = java.awt.GridBagConstraints.REMAINDER
add(help_text2, c)
add(Swing.VStrut(20), c)
add(close_button3,c)
background = java.awt.Color.yellow
border = Swing.EmptyBorder(15, 15, 15, 15)
//
}//10
listenTo(close_button3)
reactions += {//11
case ButtonClicked(b3) => dispose()
}//11
}//8
}//7
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
listenTo(close_button)
reactions += {
case ButtonClicked(b2) =>
if(b2.equals(close_button)) exit(0)
}
}//2
}//1