-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80a2085
commit d0685a0
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.atal.butterfly | ||
|
||
import scala.swing._ | ||
import scala.swing.event._ | ||
|
||
/** | ||
* A simple swing demo. | ||
*/ | ||
object HelloWorld extends SimpleSwingApplication { | ||
def top = new MainFrame { | ||
title = "Hello, World!" | ||
|
||
object editor extends Label { | ||
var buffer = new Buffer("") | ||
var _cursor = 0 | ||
|
||
text = buffer.toString() | ||
preferredSize = new Dimension(1000,500) | ||
|
||
listenTo(button) | ||
reactions += { | ||
case ButtonClicked(button) => | ||
if(input.text != "") | ||
{ | ||
buffer.insert(input.text, _cursor) | ||
_cursor += input.text.length | ||
text = buffer.toString() | ||
input.text = "" | ||
} | ||
} | ||
} | ||
|
||
object button extends Button { | ||
text = "Insert" | ||
} | ||
|
||
val input = new TextField(100) | ||
|
||
contents = new BorderPanel { | ||
add(editor, BorderPanel.Position.North) | ||
add(input, BorderPanel.Position.West) | ||
add(button, BorderPanel.Position.East) | ||
border = Swing.EmptyBorder(10, 10, 10, 10) | ||
|
||
focusable = true | ||
requestFocus | ||
} | ||
|
||
} | ||
} | ||
|