4

I try to port some Java code to Scala.

I want to display a scala.swing.Applet in a GUI application.

With Java Swing I would do

val jframe = new JFrame() jframe.add(APPLET) jframe.setVisible(true) APPLET.setFocusCycleRoot(true) APPLET.init() APPLET.start() 

But code using Scala Swing

def top = new MainFrame { contents = APPLET } 

doesn't like the type:

error: type mismatch; found : scala.swing.Applet required: scala.swing.Component contents = APPLET 

When I try to add the Applet via the Java peers, it fails like this:

def top = new MainFrame { contents = new Panel() { peer.add(new SinglePlayerGame) } } 

I get this error message:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: scala.swing.Applet cannot be cast to javax.swing.JComponent at scala.swing.Container$Wrapper$$anon$1.componentAdded(Container.scala:43) at java.awt.Container.processContainerEvent(Container.java:2071) at java.awt.Container.processEvent(Container.java:2042) at java.awt.Component.dispatchEventImpl(Component.java:4629) at java.awt.Container.dispatchEventImpl(Container.java:2103) at java.awt.Component.dispatchEvent(Component.java:4455) at java.awt.Container.addImpl(Container.java:1081) at java.awt.Container.add(Container.java:373) 

How am I supposed to solve that problem?

2
  • 1
    found : scala.swihg.Applet What is a swihg? Is it similar to a swig with a hiccup in the middle? If that is a typo., I suggest copy/paste for I/O. Commented Oct 11, 2011 at 3:31
  • related: stackoverflow.com/questions/3379901/… Commented Oct 11, 2011 at 5:39

1 Answer 1

3

It's not written in Scala, but Subway is a simple example of a hybrid applet and application. Both JApplet and JFrame are top-level containers, and initContainer() performs the common initialization.

Note that both components require proper attention to Initial Threads.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.