Scala.use(better,Swing)
《前の記事|記事一覧|次の記事》
Scala.use(better,Swing)
Using Swing ComponentsTextDemo
* Java Tutorials Sample Code を Scala で再構成しました
《参考記事》
- How to Use Text Areas (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
- Java Tutorials Sample Code, TextDemo.java
《関連記事》
■ Scala 版
1: /* 2: * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. 3: */ 4: package components 5: 6: // ---------------------------------------- 7: // class TextDemo - TextField, TextArea 8: // ---------------------------------------- 9: import swing._ 10: object TextDemo extends MainFrame { 11: val version = TextDemo 12: .getClass.getName+": #1.0.01 a" 13: // ---------------------------------------- 14: title = "TextDemo" 15: contents = new TextDemo 16: peer.setLocationRelativeTo(null) 17: } 18: 19: // ---------------------------------------- 20: class TextDemo extends GridBagPanel { 21: val textField = new TextField(20) { 22: Command.listenTo(this) 23: } 24: val textArea = new TextArea(5, 20) { 25: editable = false 26: } 27: 28: import java.awt.GridBagConstraints 29: import GridBagPanel._ 30: new Constraints { 31: gridwidth = GridBagConstraints.REMAINDER 32: fill = Fill.Horizontal 33: add(textField, this) 34: } 35: new Constraints { 36: gridwidth = GridBagConstraints.REMAINDER 37: fill = Fill.Both 38: weightx = 1.0 39: weighty = 1.0 40: add(new ScrollPane(textArea), this) 41: } 42: 43: // ---------------------------------------- ActionListener 44: import swing.event._ 45: object Command extends Publisher { 46: reactions += { case EditDone(source) => 47: val text = source.text 48: textArea.append("%s\n" format text) 49: textField.selectAll 50: textArea.caret.position = 51: textArea.peer.getDocument.getLength 52: } 53: } 54: } 55: 56: // EOF
↑ TOP
update*13/03/08 9:44:53