Skip to content

Instantly share code, notes, and snippets.

@ymnk
Created January 8, 2009 08:52
Show Gist options
  • Select an option

  • Save ymnk/44646 to your computer and use it in GitHub Desktop.

Select an option

Save ymnk/44646 to your computer and use it in GitHub Desktop.
import swing._
import swing.event._
/**
* http://d.hatena.ne.jp/xibbar/20081203#1228294818
*/
object SimpleGui1B extends SimpleGUIApplication {
def top = new MainFrame {
title = "SimpleGui1B"
contents = new Button {
text = "click me"
reactions += {
case ButtonClicked(_) =>
text = "I've been clicked!"
}
}
size = (300, 300)
}
}
/**
* http://d.hatena.ne.jp/xibbar/20081222#1229916350
*/
object SimplePaint extends SimpleGUIApplication{
def top = new MainFrame {
title = "SimplePaint"
contents = new Panel {
implicit def d2i(d:Double):Int = d.toInt
listenTo(Mouse.clicks, Mouse.moves)
var p0:java.awt.Point = null
reactions += {
case MousePressed(_, point, _, _, _) => p0 = point
case MouseDragged(_, point, _) => {
peer.getGraphics.drawLine(p0.getX, p0.getY,
point.getX, point.getY)
p0 = point
}
}
}
size = (350, 250)
}
}
/**
* http://d.hatena.ne.jp/xibbar/20081224#1229916350
*/
import java.io.File
import javax.swing.ImageIcon
import FileChooser.SelectionMode._
import FileChooser.Result._
object JFileChooserSample extends SimpleGUIApplication{
def top = new MainFrame {
title = "JFileChooserSample"
val label = new Label
menuBar = new MenuBar {
contents += new Menu("File") {
contents += new MenuItem(Action("Open Image File...") {
val fc = new FileChooser(new File(".")){
fileSelectionMode = FilesOnly
title = "Select Image"
}
fc.showOpenDialog(label) match {
case Approve =>
val file = fc.selectedFile.getAbsolutePath
label.icon = new ImageIcon(file)
case _ =>
}
})
}
}
contents = new BorderPanel {
add(label, BorderPanel.Position.Center)
}
size = (350, 300)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment