Scala介面Pannel、Layout
點選(此處)摺疊或開啟
-
object GUI_Panel_Layout extends SimpleSwingApplication{
-
def top = new MainFrame {
-
title = "Second GUI"
-
val button = new Button {
-
text = "Scala"
-
}
-
val label = new Label {
-
text = "Here is Spark!!!"
-
}
-
contents = new BoxPanel(Orientation.Vertical) { //垂直佈局
-
contents += button
-
contents += label
-
border = Swing.EmptyBorder(50, 50, 50, 50)
-
}
-
-
listenTo(button) //監聽button,解除監聽為deafTO
-
var clicks =0
-
reactions += { //處理事件
-
case ButtonClicked(button) => { //偏函式匹配點選事件
-
clicks += 1
-
label.text = "Clicked " + clicks + " times"
-
-
}
-
}
-
}
- }
object GUI_Event extends SimpleSwingApplication {
val fileChooser = new FileChooser(new File("."))
fileChooser.title = "File Chooser"
val button = new Button {
text = "Choose a File from local"
}
val label = new Label {
text = "No any file selected yet."
}
val mainPanel = new FlowPanel {
contents += button
contents += label
}
def top = new MainFrame {
title = "Scala GUI Programing advanced!!!"
contents = mainPanel //mainPanel裡有buuton、label
listenTo(button) //監聽button
reactions += { //事件棧
case ButtonClicked(b) => {
val result = fileChooser.showOpenDialog(mainPanel) //開啟對話方塊時指定父容器
if (result == FileChooser.Result.Approve) { //如果選擇了檔案
label.text = fileChooser.selectedFile.getPath() //修改label.text
}
}
}
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28912557/viewspace-2056614/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- windows registry => control pannelWindows
- css layoutCSS
- 【Android開發入門教程】四.使用者介面之LayoutAndroid
- Scala 與設計模式(五):Adapter 介面卡模式設計模式APT
- 【Scala】Scala之ObjectObject
- layout佈局
- jquery ui layoutjQueryUI
- android預覽介面出錯,Missing styles. Is the correct theme chosen for this layout?Android
- 【Scala】Scala之TraitsAI
- Layout Inflation :Unconditional layout, inflation from view adapterViewAPT
- Flutter layout 作弊稿Flutter
- FolderCompareFrame with good layoutGo
- flex 3 rows layoutFlex
- macOS Development - Auto LayoutMacdev
- fixed layout androidAndroid
- fixed fluid layoutUI
- 【Scala】Scala之Packaging and ImportsImport
- Scala學習(六)---Scala物件物件
- 【Scala篇】--Scala初始與基礎
- 【Scala篇】--Scala中的函式函式
- Scala學習(八)---Scala繼承繼承
- Scala 簡介 [摘自 Scala程式設計 ]程式設計
- Scala學習總結(from scala for the Impatient)
- Scala學習 2 Scala物件導向物件
- Scala學習(五)---Scala中的類
- Yii2 layout 由 controller 向layout中傳遞引數值Controller
- scala入門之編寫scala指令碼指令碼
- day02-layout盒模型模型
- jQuery layout 外掛屬性jQuery
- ALV LAYOUT的設定
- CSS文字:layout-flow(轉)CSS
- Twitter開源其Scala最佳實踐Effective Scala
- Scala(四):物件物件
- Scala操作Map
- Scala操作MongoDBMongoDB
- scala學習
- Scala模式匹配模式
- Type classes in Scala