How to run scala swing app?

I am new to scala and trying to run the swing application. I use scala 2.8. I compiled the program successfully, but .. on execution it shows an error, like no such file .. can any 1 please help me?

im providing the code I'm trying to execute.

Gui.scala

import swing._

object Gui extends SimpleSwingApplication

{
    def top=new MainFrame {
        title="swing"
        val b1=new Button{
            text = "ok"
        }
    } 
}

scalac Gui.scala

it compiles successfully and creates a class file but when i try

scala Gui

he just answers

No such file

+3
source share
2 answers

Setup:

D:\src\scala_ex\ex1>dir
 Volume in drive D is Data
 Volume Serial Number is 5C88-8D6C

 Directory of D:\src\scala_ex\ex1

01.12.2010  09:25    <DIR>          .
01.12.2010  09:25    <DIR>          ..
01.12.2010  09:24               173 gui.scala
               1 File(s)            173 bytes
               2 Dir(s)  24 575 205 376 bytes free

D:\src\scala_ex\ex1>more gui.scala
import swing._

object Gui extends SimpleSwingApplication {
  def top = new MainFrame {
    title = "swing"
    val b1 = new Button{
      text = "ok"
    }
  }
}

D:\src\scala_ex\ex1>scalac -version
Scala compiler version 2.8.1.final -- Copyright 2002-2010, LAMP/EPFL

Compile:

D:\src\scala_ex\ex1>scalac gui.scala

D:\src\scala_ex\ex1>dir
 Volume in drive D is Data
 Volume Serial Number is 5C88-8D6C

 Directory of D:\src\scala_ex\ex1

01.12.2010  09:26    <DIR>          .
01.12.2010  09:26    <DIR>          ..
01.12.2010  09:26               485 Gui$$anon$1$$anon$2.class
01.12.2010  09:26               557 Gui$$anon$1.class
01.12.2010  09:26               558 Gui$.class
01.12.2010  09:26             1 467 Gui.class
01.12.2010  09:24               173 gui.scala
               5 File(s)          3 240 bytes
               2 Dir(s)  24 575 201 280 bytes free

Execute:

D:\src\scala_ex\ex1>scala -cp . Gui

And the applications are launched.

+2
source

This is not a direct cut and paste from Scala code, since an empty line between object Guiand {causes a compilation error.

, Scala 2.8, :

  • Gui $$ $1 $$ $2.class
  • Gui $$ $1.class
  • Gui $.class
  • Gui.class

, , - . , package X ( ), Gui , X, , scala X.Gui.

, Java, - .

+1

Source: https://habr.com/ru/post/1772434/


All Articles