Creating Applications with Mozilla >> 2. Getting Started >> 2.1. Simple XUL Example

Chapter 2. Getting Started

To help you start creating applications as quickly as possible, this chapter presents two "Hello World" examples that demonstrate the beginning stages of Mozilla application development.

The first example is a simple XUL file that is loaded into the browser window. This example is then expanded on by adding additional features to the XUL file, such as imported stylesheets and JavaScript functions. The second "Hello World" example shows how to turn files like these into packages, which are the modular, bundled sets of files that fit together to make Mozilla applications or new modules for the Mozilla browser.

These examples provide a context for discussing the development of Mozilla applications. The first example focuses on creating and editing the basic file types, and the second focuses on the organization and distribution of applications on the Mozilla platform.

[@more@]

第二章 新手上路

为了使你能尽快地开始创建应用程序,本章给出了两个“Hello World”例子来演示Mozilla应用程序开发的开始阶段。

第一个例子是一个可以载入浏览器窗口的简单xul文件。然后这个例子被扩展加入额外的功能,比如引入样式表和javascript函数。第二个例子则用来展示如何把文件打包使之模块化,打包在一起的文件可以作为Mozilla应用程序,或者Mozilla浏览器的新模块。

这些例子提供了用来讨论Mozilla开发的基础。第一个例子着重于建立和编辑基本的文件,第二个例子则着重于在Mozilla平台上组织和发布应用程序。

2.1. Simple XUL Example

Like all good "Hello World" applications, Example 2-1 shows one of the simplest possible examples of XUL. Although it is small, it demonstrates some important aspects of XUL programming, including the use of event handlers to add behavior and the use of a box to lay out elements properly within the window. This example also provides a context for discussing more general features of the language, such as the file format, the namespace, and some XUL programming conventions.

2.1简单的xul例子

就像所有好的“Hello World”例子一样,例子2.1展示了有可能是最简单的xul文件。尽管很小,但是它仍然演示了xul编程的几个重要方面,包括使用事件处理器来增加行为和使用box元素来在窗口对象中优雅的布置组件。这个例子也提供了环境用来讨论这门语言的一般特性,比如文件格式、名称空间和一些xul编程的惯例。

Example 2-1. Hello xFly

<?xml version="1.0"?>
<!-- Sample XUL file --&gt




Use your text editor to save the code in Example 2-1 in a file called hello.xul and then load the file in Mozilla (you can do this by using File > Open File from the browser window and browsing to where you saved the file). You should see a button in the upper-left corner of the browser window that brings up an alert box when clicked. Figure 2-1 shows an example of the alert pop-up window that appears.

使用你的文本编辑器保存例子2-1的代码并命名为hello.xul,然后使用Mozilla将文件加载。你应该可以看到浏览器窗口左上角有一个按钮,按这个按钮会弹出一个对话框。图片2-1给出了这个弹出警告框的可能的样子。

Figure 2-1. The first Hello xFly example

moz_0201.png

The next few sections describe this sample file in more detail. The covered topics include the file itself, the syntax of the markup, XUL namespaces, and the basic layout of a XUL file.

接下来的几个段落里面这个例子文件将会被更加详细地给大家描述。话题包括文件本身,标记语言的语法,xul名称空间和基本的xul文件布局。


The xFly Examples

The best way to understand the possible uses of the Mozilla framework is to look more closely at a number of various existing applications. This book highlights several Mozilla development projects, such as ChatZilla and JSLib, as examples of how some people have already started using Mozilla's XPFE technologies.

Along with these applications, you'll note the use of the name "xFly" in many examples in this chapter and elsewhere in this book. The xFly examples are used throughout Chapter 2 to Chapter 6 to show how to create and package a simple Mozilla application. An installable version of the complete xFly application can be found at http://xfly.mozdev.org.

This simple application is useful because it provides a place to start exploring the new information that you will learn about in this book. As you read more about XUL, CSS, JavaScript, and the other parts of Mozilla's development framework, you can create and edit the xFly files to see how these technologies work in practice.


关于例子xFly

理解Mozilla框架的最好的办法就是去梗近距离的观察几个已经存在的Mozilla应用程序。本书涉及了几个Mozilla开发项目,比如ChatZilla和JSLib,用来展示人们怎么使用XPFE技术。

除了这些程序以外,也许你已经注意到了这个叫做xFly的程序,出现在本书的很多例子当中,xFly被尤其用在从第二到第六章,用来演示建立和打包简单的Mozilla程序。完全的可安装版xFly可以在http://xfly.mozdev.org下载。


这个简单的程序在帮助你了解你将在这本书里面学到的信息方面很有用。在你逐步的了解了更多的关于XUL,CSS,JavaScript和Mozilla框架的其他方面的知识以后,你就可以创建和修改xFly例子的文件,来看看这些技术在实际操作中是怎么运作的了。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/1541/viewspace-1023588/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/1541/viewspace-1023588/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值