2017-02-24 8 views
0

私は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"; 

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) 
    } 
    } 
} 

どのように私は新しいウィンドウを開くことができるようになります。助けてください

答えて

1

あなたは以下のようにこれを行うことができます。ここで意図的に私はTry3の新しいインスタンスを作成します。これは先に作成したobjではなく、よりクリーンなアプローチです。

reactions += { 
    case ButtonClicked(x: Button) if x.text == "Proceed" => 
    new Try2().top.visible = true 
} 
+0

私の一日を保存していただきありがとうございます –

関連する問題