Commit 9105aeb3 authored by h2b's avatar h2b

Initialization order fixed.

parent c646d62a
......@@ -35,8 +35,8 @@ trait AwtEventDriver extends AwtScreenDriver {
import AwtEventDriver._
override protected def keyListenerOption: Option[AwtKeyListener] = Some(KeyListener)
override protected def mouseListenerOption: Option[AwtMouseListener] = Some(MouseListener)
panel.addKeyListener(KeyListener)
panel.addMouseListener(MouseListener)
private object KeyListener extends AwtKeyListener {
......
......@@ -46,7 +46,7 @@ trait AwtScreenDriver extends ScreenDriver {
import AwtScreenDriver._
import AwtScreenDriver.Localizer._
private val log = Logger(getClass) at Level.Debug
private val log = Logger(getClass) at Level.Error
private val conf = env.getDefaultScreenDevice.getDefaultConfiguration
private val image = conf.createCompatibleImage(width, height)
......@@ -65,38 +65,29 @@ trait AwtScreenDriver extends ScreenDriver {
graphics.setColor(toAwtColor(_activeColor))
}
protected def keyListenerOption: Option[KeyListener] = None
protected def mouseListenerOption: Option[MouseListener] = None
private lazy val panel = new JPanel {
protected val panel = new JPanel {
log.debug("panel entered")
override protected def paintComponent(g: Graphics): Unit = {
super.paintComponent(g)
g.drawImage(image, 0, 0, null)
}
for (l keyListenerOption) {
addKeyListener(l)
log.config("key listener installed")
}
for (l mouseListenerOption) {
addMouseListener(l)
log.config("mouse listener installed")
}
}
private lazy val frame = new JFrame {
private val frame = new JFrame {
log.debug("frame entered")
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
setLocation(p0.x, p0.y)
setTitle(title)
setResizable(false)
setJMenuBar(menuBar())
add(panel)
getContentPane.setPreferredSize(new Dimension(width, height))
pack()
setVisible(true)
setVisible(false)
}
//bonus functionality, not required by super class
private def menuBar (): JMenuBar = {
log.debug("menu bar entered")
val result = new JMenuBar
val menu = new JMenu(local(Key.File))
val item = new JMenuItem(local(Key.SaveAs))
......@@ -106,6 +97,9 @@ trait AwtScreenDriver extends ScreenDriver {
result
}
frame.setJMenuBar(menuBar())
frame.setVisible(true)
def setPixel (p: Pixel, color: Color): Unit = {
val x = p.x
val y = flipV(p.y)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment