Thank you for download our SDK!

Check your email, you have received your key and the download link.

Getting Started


Introduction to TotalCross

Github SDK:
Rich User Interfaces
Sample Store
Facebook UI Sample

TotalCross has several components including a Java based library that helps you create apps for iOS, Android, Windows, Linux and more.
You will write your code once in Java and TotalCross will generate an executable file for each supported platform.

Creating a Hello World application


1. Running in Eclipse

PRE-REQUISITES


CREATING THE PROJECT


After everything is installed, open eclipse, and follow these steps:

  • File menu, New -> Java Project
  • Project name: HelloTC
  • Check “Create separate folders for sources and class files”
  • Write down the Project location. If you want, change it accordingly
  • Click Next

  • Click the Libraries tab
  • Add External Jars
  • Add file tc.jar located in the dist folder of the TotalCross installation directory
  • After the file is added,
  • Click on the arrow to expand the jar properties
  • Double-click Source Attachment
  • Check External location
  • Click External Folder
  • Select the src folder in the TotalCross installation directory
  • Click ok
  • Click Finish

You can learn a lot by looking at the sources. Attaching the jar to the source files allows to see the javadocs and also step into the TotalCross library during debugging.

CREATING THE SOURCES


Now we will create the source file and add some code to it.

  • On the package explorer, right click src folder and type: new / Class
  • Package: tc.sample
  • Name: HelloTC
  • Finish

 

Now you have to copy and paste the sources below into the HelloTC.java. Then save it.



A few explanations from the sample:


  • Every TotalCross application has one and only one class that extends MainWindow.
  • TotalCross has some user interface styles that work on all platforms: Flat, Vista and Android.
  • The most powerful feature of TotalCross is the user interface. It uses relative positioning, where a control’s position is computed based on another one and the size is usually based on the control’s properties. An adjustment based on the font’s height can be made (+100 = font height, +50 = half font height), except for the PARENTSIZE, which uses a percentage of the parent’s width (or height).
  • The correct way to handle exceptions is to throw it until it can no longer be thrown, so that’s why we handle it in onEvent and not on doInsert.
  • The user interface is initialized in initUI and the events are handled in onEvent.

RUNNING ON ECLIPSE


Now we will run the sample as a Java application.

  • on Main tab:
  • Click menu Run / Run configurations
  • Right click Java Application / New
  • Name: HelloTC on Android
  • Project: HelloTC
  • Main class: totalcross.Launcher


  • on Arguments tab:
  • Program arguments: /scr android /r {put your key here} tc.sample.HelloTC
  • Note: you must pass the key you received by email when you subscribed or you will get an error message.

  • Click Run


When you run the program, some messages are sent to the console. If you purchased the professional version, a message like “Next SDK expiration date:” will appear. This message shows the due date that you can run and deploy applications without an internet connection before the SDK blocks. You have Always 1 week to do that. If it succeeds, the activation is done only once per day and is pretty fast.
It also shows some key emulations, which are very helpful:


F2 : TAKE SCREEN SHOT AND SAVE TO CURRENT FOLDER
F6 : MENU
F7 : BACK (ESCAPE)
F9 : CHANGE ORIENTATION
F11: OPEN KEYBOARD


For example, press the F9 key when you run the sample to simulate the screen rotation.

We can also run as an iPhone with retina display, just changing some parameters.

  • Run / Run configurations
  • Right click “HelloTC on Android” and select Duplicate
  • Name: HelloTC on iPhone
  • on Arguments tab:
  • Program arguments: /scr 1920x1080x24 /fontsize 40 /scale 0.25 /r {put your key here} tc.sample.HelloTC



When you run it in the device, TotalCross will automatically set the font size based on the device’s user interface. You can easily find these by running the TotalCrossAPI sample on your device and click on the I button at top right. In this sample we use /scale to scale down (or up) so we can see the user interface.

2. Deploying the application

There are several ways to deploy the application so you can install on a real device. You can use a Linux shell, an ANT script (there’s a sample in the TotalCross Companion), and as a Java application in Eclipse. We will use the last one.

  • Click Run / Run Configurations
  • Right-click Java Application, New
  • Name: HelloTC deploy
  • Main tab:
  • Main class: tc.Deploy


Arguments tab:

  • Program arguments: tc/sample/HelloTC.class /r {put your key here} –all
  • Working directory: Other
  • Click Workspace, select HelloTC / classes (or bin) folder



  • Click Run

It will generate installs folder with all platforms, except for iOS, because it requires a key from the Apple Developer Program. Please refer to the “TotalCross Companion” to see the other deployment options.