Dart Code: Hello World

Hello World is the prototypical first program that any programmer learns.

Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file
for details. All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.

'hi' is a simple 'hello world' Dart application that runs in the browser.

Building and running:

1. go to the top-level directory of the project:
$ cd dart/

2. build the dartc compiler:
$ ./tools/build.py --arch=ia32

3. run the htmlconverter tool, that converts the dart code to javascript:
$ python ./client/tools/htmlconverter.py client/samples/hi/hi.html -o out/

4. open the generated file in a browser:
$ google-chrome out/client/samples/hi/hi-js.html

Dart Code (hi.dart):


// Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#library('hi');

#import('dart:html');

main() {
document.query('#status').innerHTML = 'Hi, Dart';
}

HTML Code (hi.html):

<!-- Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file
     for details. All rights reserved. Use of this source code is governed by a
     BSD-style license that can be found in the LICENSE file. -->
 
<!DOCTYPE HTML>
<html>
  <head>
<link rel="stylesheet" type="text/css" href="../../view/resources/view.css"/>
<link rel="stylesheet" type="text/css" href="slider_sample.css"/>
 
    <script type="application/dart" src="slider_sample.dart"></script>
  </head>
  <body>
<h2 id="status">
      dart is not running
    </h2>
<div id="menu"></div>
<div id="message"></div>
<div id="next">Next</div>
<div id="prev">Prev</div>
 
  </body>
</html>

Try out this Dart Code or create your own: clic

 

:: Link

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s