免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1087 | 回复: 0
打印 上一主题 下一主题

Applet(一):Windows和Applet [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-08-03 15:06 |只看该作者 |倒序浏览
窗口及小应用程序
Creating windows  and applets [color="#000000"]Java1.0设计的初衷是方便程序员创建出可以在各种操作平台下面看起来都相同的效果的用户界面。[color="#000000"]这个目标并没有真正实现. 相反, Java 1.0 [color="#000000"]Abstract Window Toolkit [color="#000000"](AWT) 产生的GUI在所有系统下面看起来非常普通.并且限制相当严格: (1)只能使用四种字体 (2)不能访问操作系统中一些重要的GUI元素. The Java 1.0 AWT 开发模式是笨拙的,非面向对象的. [color="#000000"]在Java 1.1 AWT事件模式中这些得到了大幅度的改进, 随着Java Bean的引入,开发模式更清晰,更面向对象化, a component programming model that is particularly oriented toward the easy creation of visual programming environments. Java 1.2通过增加Java Foundation Classes (JFC)完成了从旧的Java 1.0 AWT的转换[color="#000000"], GUI部分有了新名称“Swing.” 这些易于理解使用的Java Beans. [color="#000000"]其中的一个目的是创建可以在浏览器中运行的小程序[color="#000000"]applets[color="#000000"].由于在它们完成功能情况下首先是安全的,Applets是非常有用的支持客户端编程的工具. [color="#000000"]使用applet编程非常严格,Java run-time安全体制会帮你监管,就像“inside the sandbox(沙盒),”工作. Java 1.1 offers digital signing for applets so you can choose to allow trusted applets to have access to your machine. However, you can also step outside the sandbox and write regular applications, in which case you can access the other features of your OS. We’ve been writing regular applications all along in this book, but they’ve been [color="#000000"]console applications [color="#000000"]without any graphical components. AWT也用来创建GUI界面for regular applications. [color="#000000"]本章第一部分首先使用旧的AWT,学习旧的AWT的确有点痛苦,可是却非常必要,因为你可以读懂和维护旧的使用AWT写的代码. 有些使用未升级的Java版本搭建的环境下是需要使用旧的AWT写代码.第二部分学习使用Java 1.1中新AWT的结构 (如果可能编程序的时候尽量使用新的工具.)最后使用新的JFC/Swing组件. [color="#000000"]为什么要是用AWT?  [color="#000000"]One of the problems with the “old” AWT that you’ll learn about in this chapter is that it is a poor example of both object-oriented design and GUI development kit design. It throws us back into the dark ages of programming (some suggest that the ‘A’ in AWT stands for “awkward,” “awful,” “abominable,” etc.). You must write lines of code to do [color="#000000"]everything[color="#000000"], including tasks that are accomplished much more easily using [color="#000000"]resources[color="#000000"] in other environments. [color="#000000"]Java 1.1解决了其中搭大部分问题,因为:
  • [color="#000000"]The new AWT in Java 1.1 is a much better programming model and a significant step towards a better library. Java Beans is the framework for that library.
  • [color="#000000"]“GUI builders” (visual programming environments) will become [color="#000000"]de rigeur [color="#000000"]for all development systems. Java Beans and the new AWT allow the GUI builder to write code for you as you place components onto forms using graphical tools. Other component technologies such as ActiveX will be supported in the same fashion. [color="#000000"]为什么要学旧的AWT? “因为它就在那里(there).” 这种情况下, “there” has a much more ominous meaning and points to a tenet of object-oriented library design: [color="#000000"]Once you publicize a component in your library, you can never take it out [color="#000000"]. If you do, you’ll wreck somebody’s existing code. In addition, there are many existing code examples out there that you’ll read as you learn about Java and they all use the old AWT. [color="#000000"]The AWT 必须接触本地系统GUI构件, which means that it performs a task that an applet cannot otherwise accomplish. 不安全的applet不能直接调用OS系统因为它有可能破坏用户的系统,它访问系统的唯一方法是调用Java编著库来操作,鄙俗“在屏幕上画一个窗口” . The original model that Sun created is that this “trusted library” will be provided only by the trusted vendor of the Java system in your Web browser, and the vendor will control what goes into that library. [color="#000000"]But what if you want to extend the system by adding a new component that accesses functionality in the OS? Waiting for Sun to decide that your extension should be incorporated into the standard Java library isn’t going to solve your problem. The new model in Java 1.1 is “trusted code” or “signed code” whereby a special server verifies that a piece of code that you download is in fact “signed” by the stated author using a public-key encryption system. This way, you’ll know for sure where the code comes from, that it’s Bob’s code and not just someone pretending to be Bob. This doesn’t prevent Bob from making mistakes or doing something malicious, but it does prevent Bob from shirking responsibility – anonymity is what makes computer viruses possible. A digitally signed applet – a “trusted applet” – in Java 1.1 [color="#000000"]can[color="#000000"] reach into your machine and manipulate it directly, just like any other application you get from a “trusted” vendor and install onto your computer. [color="#000000"]But the point of all this is that the old AWT is [color="#000000"]there[color="#000000"]. There will always be old AWT code floating around and new Java programmers learning from old books will encounter that code. Also, the old AWT is worth studying as an example of poor library design. The coverage of the old AWT given here will be relatively painless since it won’t go into depth and enumerate every single method and class, but instead give you an overview of the old AWT design.

    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8682/showart_38993.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP