Created
November 5, 2011 05:36
-
-
Save toby55kij/1341153 to your computer and use it in GitHub Desktop.
コードで自己紹介 by toby55kij
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
import groovy.beans.Bindable | |
import groovy.json.JsonSlurper | |
import groovy.swing.SwingBuilder | |
import java.awt.Font | |
import javax.swing.DefaultComboBoxModel | |
import javax.swing.JFrame | |
import javax.swing.JTextField | |
def msgs = new JsonSlurper().parseText '''{ | |
"title":"自己紹介", | |
"keys":["氏名", "年齢", "在住", "仕事", "E-Mail", "Twitter"], | |
"contents":{ | |
"氏名":"速水 康晴", | |
"年齢":"39", | |
"在住":"新潟県新潟市", | |
"仕事":"プログラマ(Java,ActionScript)", | |
"E-Mail":"toby55kij@gmail.com", | |
"Twitter":"@toby55kij" | |
} | |
}''' | |
class TextModel { | |
@Bindable String key | |
@Bindable String value | |
} | |
def textModel = new TextModel() | |
SwingBuilder.edtBuilder { | |
frame(title: msgs.title, show: true, | |
location:[20, 100], pack:true, | |
defaultCloseOperation: JFrame.DISPOSE_ON_CLOSE) { | |
vbox { | |
hbox { | |
comboBox id: 'keys', | |
model: (msgs.keys as Vector) as DefaultComboBoxModel, | |
actionPerformed: { | |
textModel.key = keys.selectedItem | |
textModel.value = msgs.contents[keys.selectedItem] | |
}, | |
focusable: false, | |
selectedIndex: 0 | |
button text: 'Next', defaultButton: true, | |
actionPerformed: { | |
keys.selectedIndex = (keys.selectedIndex + 1) % keys.model.size | |
} | |
} | |
textField columns: 20, editable: false, font: Font.decode('Dialog 40'), | |
horizontalAlignment: JTextField.CENTER, | |
text: bind { textModel.key + ' : ' + textModel.value } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment