c# to javascript, actionscript

June 22, 2009

new example: ThreadingExample

Filed under: jsc — Tags: , , , — zproxy @ 9:08 am

In this example I am going to demonstrate how to write a java applet with a background thread.

Here is a list of the use cases for code written as such:

  • Java Applet
  • Java Console Application
  • .NET Console

Additionally I have added support for mouse enter and leave events the java way. While in .net it is easy to subscribe to events using anonymous delegates, such a feature is not yet supported by jsc compiler for java target. It could be resolved in the future releases by adding support for generics and build dynamic invokation on reflection. Google App Engine and Android markets are probably going to trigger that update.

For what do we need a background thread

I have created a simple infinite incrementing loop to serve as our business layer. There is a special class ThreadedAction, which abstracts away thread creation, which in turn differs from .net to java from being delegate based to being interface based.

24 while (true)

25 {

26 Value++;

27

28 // we should be running on our own thread

29 // which enables us to loop forever and sleep when tired :)

30 Thread.Sleep(100);

31 }

How do we spawn a new thread

As I enjoy the AtDelay and AtInterval extension methods I make use of while programming for actionscript and javascript, I had to implement something similar for the threading API. Therefor spawning a new thread is dead simple:

57 CurrentThreadedAction = 0.AtDelay(Current);

Why not try to test it out running as a console.

The assembly has been defined as a console exe. Hitting F5 in debug build will show you the console asking your input when to stop the computation.

ConsoleScreenshot

We now saw that our threaded application does run inside .net. It is time to run it on java virtual machine. To do that we need to build our project with release build. This will trigger jsc to genereta java source code and afterwards java compiler will add final magic.

You cannot just press F5 now, instead you should start run.jar.bat. I am using Scite and by double clicking on the bat file Scite shows up in which I can press F5.

JVMConsoleScreenshot

Notice that, only the title is different.

Let’s add an applet interface

Console applications are cool, but applets also have its role to play in our example. The applet form is set up in two steps. In file DemoApplet.Designer.cs I am going to define the buttons and attach handlers.

37 this.Button3 = new Button {};

38 this.Button3.setLabel(“Compute”);

39 this.Button3.addMouseListener(new Button3_MouseEnter_Handler { Target = this });

40 this.Button3.addMouseListener(new Button3_MouseExit_Handler { Target = this });

41

42 base.add(Button3);

I know you would rather use delegates – I would, but I cannot just yet. In file DemoApplet.cs I am going to define the actual handlers.

97 #region [this.Button3_MouseEnter]

98 [Script]

99 class Button3_MouseEnter_Handler : MouseListener_MouseEnter

100 {

101 public ThreadingExample Target;

102

103 protected override void Invoke()

104 {

105 Target.Button3_MouseEnter();

106 }

107 }

108 #endregion

109

110 public void Button3_MouseEnter()

111 {

112 this.Button1.Enabled = false;

113 this.Button2.Enabled = false;

114

115 this.MyComputation.Start();

116

117 this.Button1.setLabel(“start @ “ + MyComputation.Current.Value);

118 this.Button2.setLabel(“Stop computing”);

119

120 }

In the applet I could start the computation either by explicitly clicking on the start button or hovering your mouse on the third button.

Summary

In this example I demonstrated how to write a threaded applet which handles mouse enter and mouse leave events for starting and stopping computation.

ThreadingExample

June 9, 2009

Minecraft

Filed under: games — Tags: , , — zproxy @ 7:01 pm

http://www.minecraft.net/img/logo.gif

Check out this cool java game :)

minecraft by you.

May 1, 2009

Mandelbrot

Filed under: jsc — Tags: , , , , , , , — zproxy @ 9:46 am

One single static C# class implementation to rule them all.

The other day I found an example of Mandelbrot implementation for Silverlight. I have created this example solution to serve as a reference implementation.

This single Mandelbrot implementation is reachable for these platforms:

  1. Windows Forms
  2. Windows Presentation Foundation
  3. Silverlight (3.0 beta)
  4. Java Applet
  5. Flash
  6. Javascript (Firefox, Safari)

For those of you who are new, jsc compiler is going to generate source code for you. While you write your algorithm in C# in current case it can be retranslated to java, actionscript, c and javascript to enable other platforms. Do leave a comment if you would like to know more about it.

November 20, 2008

AvalonWebApplication with PHP backend

Filed under: jsc — Tags: , , , , , , , — zproxy @ 7:41 pm

I have created a new project template that demonstrates most of what jsc is capable of. Soon I will publish it on the sourceforge with a tutorial how to get started using it.

Long story short – Here is an application which demonstrates the following features all written in C#:

  1. PHP Backend
  2. JavaScript (WPF)
  3. ActionScript (WPF)
  4. Java Applet

Update: Moved the example to sourceforge and removed the querystring switch.

July 17, 2008

Two New Examples

Filed under: jsc — Tags: , , , , , , — zproxy @ 3:11 pm




The RayCaster is based on this source and is just what you need to when you start making one of these Wolf3D games. The ZIndex demo shows how you could emulate the missing z-index property in flash 9.

June 12, 2008

Jsc June Refresh 2

Filed under: jsc — Tags: , , , , , , , , , , — zproxy @ 4:29 pm

Some updates to the compiler and the framework: Download jsc here. (Others already have!)

Added two Java project templates.

Visit our google groups.

Tutorials to read when just starting with jsc:

This release contains the following Project Templates:

OrcasAppletApplication – C# to Java Applet
OrcasFlashApplication – C# to ActionScript
OrcasScriptApplication – C# to JavaScript
OrcasVisualBasicFlashApplication – VB.NET to ActionScript
OrcasVisualBasicScriptApplication – VB.NET to JavaScript
OrcasWebApplication – C# to JavaScript as Microsoft Web Application
OrcasWebSite – C# to JavaScript as Microsoft ASP.NET Web Site
OrcasJavaConsoleApplication – C# to Java as Console Application
OrcasNativeJavaConsoleApplication – C# to Java as Console Application with JNI bindings.

Have a look at some old screencasts:

June 6, 2008

Jsc June Refresh

Filed under: jsc — Tags: , , , , , , , , , , — zproxy @ 2:43 pm

Some updates to the compiler and the framework: Download jsc here.

Most important update was fixing the virtual + override semantics for jsc:actionscript. It’ did not allow to combine multiple events for example.

Visit our google groups.

Tutorials to read when just starting with jsc:

This release contains the following Project Templates:

OrcasAppletApplication – C# to Java Applet
OrcasFlashApplication – C# to ActionScript
OrcasScriptApplication – C# To JavaScript
OrcasVisualBasicFlashApplication – VB.NET to ActionScript
OrcasVisualBasicScriptApplication – VB.NET to JavaScript
OrcasWebApplication – C# to JavaScript as Microsoft Web Application
OrcasWebSite – C# to JavaScript as Microsoft ASP.NET Web Site

Writing code in VB.NET for flash looks like this:

Blog at WordPress.com.