1 / 16

JAVA APPLETS - 3

JAVA APPLETS - 3. By: Ms. Humaira Siddiqui. Inter-Applet Communication. Example : The HTML file. <HTML> <TITLE> Currency Conversion Demo </TITLE> <BODY> <APPLET CODE=“ GUI.class ” NAME=“first” WIDTH=300 HEIGHT=200> </APPLET>

hovan
Télécharger la présentation

JAVA APPLETS - 3

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. JAVA APPLETS - 3 By: Ms. HumairaSiddiqui

  2. Inter-Applet Communication

  3. Example : The HTML file <HTML> <TITLE> Currency Conversion Demo </TITLE> <BODY> <APPLET CODE=“GUI.class” NAME=“first” WIDTH=300 HEIGHT=200> </APPLET> <APPLET CODE=“Compute.class” NAME=“second” WIDTH=10 HEIGHT=10> </APPLET> </BODY> </HTML>

  4. Example : The GUI.java applet import java.awt.*; import java.applet.*; public class GUI extends Applet { public void init() { Panel pan = new Panel(); pan.setLayout (new.FlowLayout()); pan.add (new Label(“Riyals”)); TextField r = new TextField(“”, 8); pan.add(r); pan.add (new Label(“Currency”)); TextFieldnc = new TextField(“”, 10); pan.add(nc);

  5. pan.add (new Label(“Result of conversion”)); TextField result = new TextField(“”, 50); pan.add(result); add(“South”, pan); } public booleanhandleEvent(Event v) { if(v.id==Event.WINDOW_DESTROY) System.exit(0); return super.handleEvent(v); }

  6. public boolean action(Event v, Object arg) { int x = Format.atoi(r.getText()); String y = nc.getText(); Compute p = (Compute) getAppletContext.getApplet(“second”); result.setText(r.getText) + “Riyals =” + p.convert(x, y) + nc.getText(); } private TextField r, nc; }

  7. Example : The Compute.java applet import java.awt.*; import java.applet.*; public class Compute extends Applet { public void init() { Panel outp = new Panel(); pan.setLayout (new.FlowLayout()); outp.add (new Label(“Result of conversion:”)); TextField result = new TextField(“”, 50); outp.add(result); add (“South”, outp); }

  8. public int convert(int riyal, String curr) { if(curr.equals “dollar”) return(riyal/4); if(curr.equals “euro”) return(riyal/5); if(curr.equals “xyz”) return(riyal …);

  9. Accessing Image Files

  10. Introduction • An image file can be retrieved from an applet using the getimage() method, which has two different forms: • image getImage(URL a) • image getImage(URL a, String path) ->First form gets an image file specified from the URL ->Second form uses a string to provide a path relative to the URL in the first argument • Typical example of use: • image logo = getImage(getDocumentBase(), “images/logo.gif”);

  11. An Example • Displays two images alternately in response to some window event: <HTML> <APPLET CODE = “ImageView.class” WIDTH=650 HEIGHT=300> <PARAM NAME=“M1” VALUE=“face1.gif”> <PARAM NAME=“M2” VALUE=“face2.gif”> </APPLET> </HTML>

  12. import java.awt.*; import java.applet.*; public class ImageViewextends Applet { boolean flag=true; image x, y; public void init() { x=getImage(getDocumentBase(), getParameter(“M1”)); y=getImage(getDocumentBase(), getParameter(“M2”)); }

  13. public void paint(Graphics g) { if(flag) { g.drawImage(x, 0, 0, this); flag=false; } else { g.drawImage(y, 0, 0, this); flag=true; } } }

  14. Accessing AudioFiles

  15. Introduction • An audio file can be retrieved using the getAudioClip() method, which has two forms: • AudioClipgetAudioClip(URL a) • AudioClip get(URL a, String path) ->First form gets an audio file specified from the URL ->Second form uses a string to provide a path relative to the URL in the first argument • To play an audio clip, we can use the play() method, which also has two different forms: • void play(URL a) • void play(URL a, String path) ->With the same interpretation.

  16. Typical uses of play(): 1 ->AudioClip anthem=getAudioClip(getDocumentBase(), “anthem.au”); Anthem.play(); 2 ->play(getDocumentBase(), “anthem.au”);

More Related