How to use scala.swing.applet in a Scala Swing app?

I am trying to port some Java code to Scala.

I want to display 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 } 

don't like type:

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

When I try to add an applet through Java nodes, it fails as follows:

 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 should I solve this problem?

+4
source share
1 answer

It is 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 common initialization.

Please note that both components require due attention to the initial threads .

+3
source

All Articles