Created
September 30, 2008 15:11
-
-
Save ymnk/13849 to your computer and use it in GitHub Desktop.
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 swing._ | |
import swing.event._ | |
import scala.concurrent.ops.spawn | |
object TakahashiMethodInScalaSwing extends SimpleGUIApplication { | |
def top = new MainFrame { | |
title = "TakahashiMethodInScalaSwing" | |
/** | |
* MainFrame has already defined | |
* case WindowClosing(_) => System.exit(1) | |
*/ | |
// peer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) | |
val textLabel = new Label("Input Text") { | |
import java.awt.Font | |
import javax.swing.SwingConstants._ | |
peer.setHorizontalAlignment(CENTER) | |
peer.setFont(new Font("monospaced", Font.PLAIN, 80)); | |
} | |
contents = new BorderPanel { | |
import BorderPanel.Position._ | |
val button = new Button("Quit") { | |
reactions += { | |
case ButtonClicked(_) => System.exit(0) | |
} | |
} | |
this.add(button, South) | |
this.add(textLabel, Center) | |
} | |
size = (800, 600) | |
val texts = new Iterator[String]{ | |
private var n = 0 | |
private var p = nextPage | |
private def nextPage = { | |
import io.Source | |
n+=1 | |
val url = "http://nkst.jp/vote2/novel.php?auther=20080001&page="+n | |
Source.fromURL(url, "SJIS").mkString. | |
split("\r\n").mkString. | |
split("<br />"). | |
map(_.trim). | |
filter(_.length>0). | |
filter(!_.startsWith("<")). | |
elements | |
} | |
def next = p.next | |
def hasNext = p.hasNext || {p = nextPage; p.hasNext} | |
} | |
spawn{ | |
for(t <- texts){ | |
textLabel.text = t | |
Thread.sleep(3000L) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment