Swing 单击按钮时缩放打开的框架
我正在用scala创建一个应用程序。我想在点击按钮时打开一个框架。我是斯卡拉的新手。这是密码Swing 单击按钮时缩放打开的框架,swing,scala,Swing,Scala,我正在用scala创建一个应用程序。我想在点击按钮时打开一个框架。我是斯卡拉的新手。这是密码 import scala.swing._; import java.io._; import scala.swing.event._; import javax.swing.ImageIcon; object Try1 extends SimpleSwingApplication { def top = new MainFrame { title = "First Swing App"; v
import scala.swing._;
import java.io._;
import scala.swing.event._;
import javax.swing.ImageIcon;
object Try1 extends SimpleSwingApplication {
def top = new MainFrame {
title = "First Swing App";
val button = new Button {
text = "Proceed"
}
contents = new BoxPanel(Orientation.Vertical) {
contents += button
border = Swing.EmptyBorder(30, 30, 30, 30)
}
val obj = new Try2();
listenTo(button)
reactions += {
case ButtonClicked(button) =>
//here 2nd frame must be open
}
}
要打开的窗口的代码如下所示
import javax.swing.ImageIcon
import scala.swing._
class Try2 extends SimpleSwingApplication {
def top = new MainFrame {
title = "Second Swing App";
val button = new Button {
text = "Proceed"
}
contents = new BoxPanel(Orientation.Vertical) {
contents += button
border = Swing.EmptyBorder(30, 30, 30, 30)
}
}
}
我怎样才能打开新窗口。请帮助您可以执行如下所示的操作。这里我有意创建一个新的Try2实例,而不是先前创建的
obj
,因为这是一种更干净的方法
reactions += {
case ButtonClicked(x: Button) if x.text == "Proceed" =>
new Try2().top.visible = true
}
谢谢你救了我一天