Reputation: 1214
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.
Upvotes: 0
Views: 34
Reputation: 1533
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
Upvotes: 0
Reputation: 22553
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.
Upvotes: 3