1 / 23

Applets Programming

Enabling Application Delivery Via the Web. Applets Programming. Introduction. Applets are small Java programs that are embedded in Web pages. They can be transported over the Internet from one computer (web server) to another (client computers).

hua hua
Download Presentation

Applets Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Enabling Application Delivery Via the Web Applets Programming

  2. Introduction • Applets are small Java programs that are embedded in Web pages. • They can be transported over the Internet from one computer (web server) to another (client computers). • They transform web into rich media and support the delivery of applications via the Internet.

  3. Applet: Making Web Interactive and Application Delivery Media 2 5 1 3 4 Accessing from Your Organisation APPLET Development “hello.java” AT SUN.COM The browser creates a new window and a new thread and then runs the code hello.class AT SUN’S WEB SERVER Create Applet tag in HTML document Hello Java <app= “Hello”> The Internet Hello

  4. How Applets Differ from Applications • Although both the Applets and stand-alone applications are Java programs, there are certain restrictions are imposed on Applets due to security concerns: • Applets don’t use the main() method, but when they are load, automatically call certain methods (init, start, paint, stop, destroy). • They are embedded inside a web page and executed in browsers. • They cannot read from or write to the files on local computer. • They cannot communicate with other servers on the network. • They cannot run any programs from the local computer. • They are restricted from using libraries from other languages. • The above restrictions ensures that an Applet cannot do any damage to the local system.

  5. Building Applet Code: An Example //HelloWorldApplet.java import java.applet.Applet; import java.awt.*; public class HelloWorldApplet extends Applet { public void paint(Graphics g) { g.drawString ("Hello World of Java!",25, 25); } }

  6. Embedding Applet in Web Page <HTML> <HEAD> <TITLE> Hello World Applet </TITLE> </HEAD> <body> <h1>Hi, This is My First Java Applet on the Web!</h1> <APPLET CODE="HelloWorldApplet.class" width=500 height=400> </APPLET> </body> </HTML>

  7. Accessing Web page (runs Applet)

  8. Applet Life Cycle • Every applet inherits a set of default behaviours from the Applet class. As a result, when an applet is loaded, it undergoes a series of changes in its state. The applet states include: • Initialisation – invokes init() • Running – invokes start() • Display – invokes paint() • Idle – invokes stop() • Dead/Destroyed State – invokes destroy()

  9. Applet States • Initialisation – invokes init() – only once • Invoked when applet is first loaded. • Running – invokes start() – more than once • For the first time, it is called automatically by the system after init() method execution. • It is also invoked when applet moves from idle/stop() state to active state. For example, when we return back to the Web page after temporary visiting other pages. • Display – invokes paint() - more than once • It happens immediately after the applet enters into the running state. It is responsible for displaying output. • Idle – invokes stop() - more than once • It is invoked when the applet is stopped from running. For example, it occurs when we leave a web page. • Dead/Destroyed State – invokes destroy() - only once • This occurs automatically by invoking destroy() method when we quite the browser.

  10. Applet Life Cycle Diagram init() Born Begin stop() start() Running Idle destroy() paint() start() Dead End

  11. Passing Parameters to Applet <HTML> <HEAD> <TITLE> Hello World Applet </TITLE> </HEAD> <body> <h1>Hi, This is My First Communicating Applet on the Web!</h1> <APPLET CODE="HelloAppletMsg.class" width=500 height=400> <PARAM NAME="Greetings" VALUE="Hello Friend, How are you?"> </APPLET> </body> </HTML>

  12. Applet Program Accepting Parameters //HelloAppletMsg.java import java.applet.Applet; import java.awt.*; public class HelloAppletMsg extends Applet { String msg; public void init() { msg = getParameter("Greetings"); if( msg == null) msg = "Hello"; } public void paint(Graphics g) { g.drawString (msg,10, 100); } } This is name of parameter specified in PARAM tag; This method returns the value of paramter.

  13. HelloAppletMsg.html

  14. What happen if we don’t pass parameter? See HelloAppletMsg1.html <HTML> <HEAD> <TITLE> Hello World Applet </TITLE> </HEAD> <body> <h1>Hi, This is My First Communicating Applet on the Web!</h1> <APPLET CODE="HelloAppletMsg.class" width=500 height=400> </APPLET> </body> </HTML>

  15. getParameter() returns null. Some default value may be used.

  16. Displaying Numeric Values //SumNums.java import java.applet.Applet; import java.awt.*; public class SumNums extends Applet { public void paint(Graphics g) { int num1 = 10; int num2 = 20; int sum = num1 + num2; String str = "Sum: "+String.valueOf(sum); g.drawString (str,100, 125); } }

  17. SunNums.html <HTML> <HEAD> <TITLE> Hello World Applet </TITLE> </HEAD> <body> <h1>Sum of Numbers</h1> <APPLET CODE="SumNums.class" width=500 height=400> </APPLET> </body> </HTML>

  18. Applet – Sum Numbers

  19. Interactive Applets • Applets work in a graphical environment. Therefore, applets treats inputs as text strings. • We need to create an area on the screen in which use can type and edit input items. • We can do this using TextField class of the applet package. • When data is entered, an event is generated. This can be used to refresh the applet output based on input values.

  20. Interactive Applet Program..(cont) //SumNumsInteractive..java import java.applet.Applet; import java.awt.*; public class SumNumsInteractive extends Applet { TextField text1, text2; public void init() { text1 = new TextField(10); text2 = new TextField(10); text1.setText("0"); text2.setText("0"); add(text1); add(text2); } public void paint(Graphics g) { int num1 = 0; int num2 = 0; int sum; String s1, s2, s3; g.drawString("Input a number in each box ", 10, 50); try { s1 = text1.getText(); num1 = Integer.parseInt(s1); s2 = text2.getText(); num2 = Integer.parseInt(s2); } catch(Exception e1) {}

  21. Interactive Applet Program. sum = num1 + num2; String str = "THE SUM IS: "+String.valueOf(sum); g.drawString (str,100, 125); } public boolean action(Event ev, Object obj) { repaint(); return true; } }

  22. Interactive Applet Execution

  23. Summary • Applets are designed to operate in Internet and Web environment. They enable the delivery of applications via the Web. • This is demonstrate by things that we learned in this lecture such as: • How do applets differ from applications? • Life cycles of applets • How to design applets? • How to execute applets? • How to provide interactive inputs?

More Related

代做工资流水公司唐山背调工资流水样本滁州银行流水账模板武汉做入职流水大庆制作公司银行流水南京代开车贷工资流水邯郸查个人工资流水湖州个人工资流水 开具济南查询银行流水修改石家庄公司流水样本湛江离职证明制作泰安代办自存银行流水舟山工作收入证明代开淄博做对公银行流水济南打印车贷工资流水佛山签证流水样本滁州做企业对私流水常州银行流水账单多少钱烟台贷款银行流水代办嘉兴工资流水账单打印台州工资流水单公司银川打流水账单厦门制作背调银行流水苏州银行流水修改办理开封代做银行对公流水石家庄转账银行流水开具苏州开薪资流水长沙银行流水电子版模板深圳银行对公流水查询廊坊车贷工资流水 公司遵义薪资流水样本香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声卫健委通报少年有偿捐血浆16次猝死汪小菲曝离婚始末何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言男子被猫抓伤后确诊“猫抓病”周杰伦一审败诉网易中国拥有亿元资产的家庭达13.3万户315晚会后胖东来又人满为患了高校汽车撞人致3死16伤 司机系学生张家界的山上“长”满了韩国人?张立群任西安交通大学校长手机成瘾是影响睡眠质量重要因素网友洛杉矶偶遇贾玲“重生之我在北大当嫡校长”单亲妈妈陷入热恋 14岁儿子报警倪萍分享减重40斤方法杨倩无缘巴黎奥运考生莫言也上北大硕士复试名单了许家印被限制高消费奥巴马现身唐宁街 黑色着装引猜测专访95后高颜值猪保姆男孩8年未见母亲被告知被遗忘七年后宇文玥被薅头发捞上岸郑州一火锅店爆改成麻辣烫店西双版纳热带植物园回应蜉蝣大爆发沉迷短剧的人就像掉进了杀猪盘当地回应沈阳致3死车祸车主疑毒驾开除党籍5年后 原水城县长再被查凯特王妃现身!外出购物视频曝光初中生遭15人围殴自卫刺伤3人判无罪事业单位女子向同事水杯投不明物质男子被流浪猫绊倒 投喂者赔24万外国人感慨凌晨的中国很安全路边卖淀粉肠阿姨主动出示声明书胖东来员工每周单休无小长假王树国卸任西安交大校长 师生送别小米汽车超级工厂正式揭幕黑马情侣提车了妈妈回应孩子在校撞护栏坠楼校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变老人退休金被冒领16年 金额超20万西藏招商引资投资者子女可当地高考特朗普无法缴纳4.54亿美元罚金浙江一高校内汽车冲撞行人 多人受伤

代做工资流水公司 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化