// this example shows the possibility

// of loading classes dynamically

// without having specified their

// classpath at startup. this makes

// use of the '/classes' command

// added in SwingOSC 0.42

// note: requires an active connection to the internet

(

g = SwingOSC.default;

g.sendMsg( '/classes', \add, "http://java.sun.com/applets/other/Bubbles/classes/Bubbles.class" );

g.sendMsg( '/local', \applet, '[', '/new', \Bubbles, ']' , \frame, '[', '/new', 'java.awt.Frame', "MyApplet", ']' );

g.sendMsg( '/set', \frame,

\layout, '[', '/new', 'java.awt.BorderLayout', ']',

\resizable, false,

\size, '[', '/new', 'java.awt.Dimension', 500, 500, ']',

\locationRelativeTo, '[', '/ref', \null, ']' // this places frame in center of screen

);

g.sendMsg( '/method', \frame, \add, '[', '/ref', \applet, ']' );

g.sendMsg( '/method', \applet, \init );

g.sendMsg( '/method', \applet, \start );

g.sendMsg( '/set', \frame, \visible, true );

)

(

g.sendMsg( '/method', \applet, \stop );

g.sendMsg( '/method', \frame, \dispose );

)

// same using JavaObject class

// note that the sendMsg style can be a bit more efficient

// as you can set a couple of properties at once using /set,

// but using JavaObject the readability is much better and

// you syntax is very close to native java.

(

g = SwingOSC.default;

g.addClasses( "http://java.sun.com/applets/other/Bubbles/classes/Bubbles.class" );

a = JavaObject( 'Bubbles', g );

f = JavaObject( 'java.awt.Frame', g, "MyApplet" );

f.setLayout( JavaObject( 'java.awt.BorderLayout', g ));

f.setResizable( false );

f.setSize( 500, 500 );

f.setLocationRelativeTo( nil );

f.add( a );

a.init;

a.start;

f.setVisible( true );

)

(

a.stop;

f.dispose;

)

Explanation

- To add entries to SwingOSC's class path, use the command [ '/classes', \add, ... ] with a list of paths. A path can be a jar archive, a folder containing classes or a single class. The paths have to be specified in URL format. Here we add a class file on Sun's website, an applet that fortunately doesn't call getParameter and therefore can be displayed in a regular frame without having to create an applet stub.

// last mod: 30-jul-07 sciss