0

So I'm fairly new to programming, right now I'm trying to get a better understanding of how to program across multiple files.

How better to do this, than to try.

I'm also using an IDE for pretty much the first time, so that might be what's tripping me up.

Onto the meat:

So I have one file while should be the main method. In my head, it takes args, and calls the window object (it can't do anything while the window is open, right?).

package CViewerMain

import CViewerMainWindow

/**
  * Created by Matt on 6/21/16.
  */
class CViewer {
  def main(args: Array[String]): Unit = {
    var coreWindow = new CViewerMainWindow
    coreWindow.main
    return
  }
}

That method calls CViewerMainWindow, which is in the second file. Also, the IDE (Intellij IDEA) is telling me that the second one's package name does not match the directory structure, but both the packages are in the same dir.

package CViewerWindow

import scala.swing._
import swing.event.UIElementResized

/**
  * Created by Matt on 6/21/16.
  */
package object CViewerMainWindow extends SimpleSwingApplication {
  def top = new MainFrame {
    title = "Hello, World!"
    preferredSize = new Dimension(320, 240)
    // maximize
    visible = true
    contents = new Label("Here is the contents!")
    listenTo(UI.this)
    reactions += {
      case UIElementResized(source) => println(source.size)
    }
  }
}

So What I assume is going wrong, is somewhere in the process I am not giving one of the files enough/correct information about the other.

BillRobertson42
  • 12,602
  • 4
  • 40
  • 57
Jones
  • 1,154
  • 1
  • 10
  • 35

2 Answers2

3

Packages on in scala and java map pretty well onto your directory structure. If the two classes are in the same directory, they are in the same package.

So CViewerMain should be the package for the CViewerMainWindow class.

Robert Moskal
  • 21,737
  • 8
  • 62
  • 86
0

Ok based on the project structure both CViewerMain and CViewerMainWindow classes are in same folder aka package. So you need to follow Robert's Answer.

Change the below

package CViewerWindow

to

package CViewerMain
Beniton Fernando
  • 1,533
  • 1
  • 14
  • 21
  • Alright then, it's no longer complaining about that. But how to I call on it from the main function? – Jones Jun 22 '16 at 03:42