Archive for October, 2007

Multiple domain web hosting - 1187Chapter 44 .Scripting Java Applets and Plug-ins catch

Wednesday, October 31st, 2007

1187Chapter 44 .Scripting Java Applets and Plug-ins catch (IOException e) { result = AppletError: + e; } output = result; } public String fetchText() { return output; } public void init() { } public void start() { if (thread == null) { thread = new Thread(this); thread.start(); } } public void stop() { if (thread != null) { thread.stop(); thread = null; } } public void run(){ try { getFile(fileName); } catch (IOException e) { output = AppletError: + e; } } } All the work of actually retrieving the file is performed in the getFile() method (which runs immediately after the applet loads). Notice that the name of the file to be retrieved, Bill of Rights.txt, is stored as a variable near the top of the code, making it easy to change for a recompilation, if necessary. You can also modify the applet to accept the file name as an applet parameter, specified in the HTML code. Meanwhile, the only hook that JavaScript needs is the one public method called fetchText(), which merely returns the value of the output variable, which in turn holds the file s contents. This Java source code must be compiled into a Java class file (already compiled and included on the CD-ROM as FileReader.class) and placed in the same directory as the HTML file that loads this applet. Also, no explicit pathname for the text file is supplied in the source code, so the text file is assumed to be in the same directory as the applet.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

1186 Part (Hp web site) V . Putting JavaScript to Work

Wednesday, October 31st, 2007

1186 Part V . Putting JavaScript to Work Faceless applets Until LiveConnect came along, Java applets were generally written to show off data and graphics to play a big role in the presentation on the page. But if you prefer to let an applet do the heavy algorithmic lifting for your pages while the HTML form elements and images (or Dynamic HTML facilities of newer browsers) do the user interface, you essentially need what I call a faceless applet. The method for embedding a faceless applet into your page is the same as embedding any applet: Use the tag. But specify only 1 pixel for both the HEIGHT and WIDTHattributes (0 has strange side effects). This setting creates a dot on the screen, which, depending on your page s background color, may be completely invisible to page visitors. Place it at the bottom of the page, if you like. To show how nicely this method can work, Listing 44-4 provides the Java source code for a simple applet that retrieves a specific text file and stores the results in a Java variable available for fetching by the JavaScript shown in Listing 44-5. The HTML even automates the loading process by triggering the retrieval of the Java applet s data from an onLoad event handler. Listing 44-4: Java Applet Source Code import java.net.*; import java.io.*; public class FileReader extends java.applet.Applet implements Runnable { Thread thread; URL url; String output; String fileName = Bill of rights.txt ; public void getFile(String fileName) throws IOException { String result, line; InputStream connection; DataInputStream dataStream; StringBuffer buffer = new StringBuffer(); try { url = new URL(getDocumentBase(),fileName); } catch (MalformedURLException e) { output = AppletError + e; } try { connection = url.openStream(); dataStream = new DataInputStream(new BufferedInputStream(connection)); while ((line = dataStream.readLine()) != null) { buffer.append(line + n ); } result = buffer.toString(); }
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

1185Chapter 44 .Scripting Java Applets and Plug-ins Very (Web hosting service)

Tuesday, October 30th, 2007

1185Chapter 44 .Scripting Java Applets and Plug-ins


Very little of the code here controls the applet only the handful of functions near the top. The rest of the code makes up the HTML user interface for the form element controls. After you open this document from the CD-ROM, be sure to click the Applet Info button to see the methods that you can script and the way that the parameter values from the JavaScript side match up with the parameters on the Java method side. Figure 44-2: Scripting more of the ScriptableClock applet Applet limitations Because of concerns about security breaches via LiveConnect, Netscape clamps down on some powers that would be nice to have via a scripted applet. The most noticeable barrier is the one that prevents applets from accessing the network under scripted control. Therefore, even though a Java applet has no difficulty reading or writing text files from the server, such capabilities even if built into an applet of your own design won t be carried out if triggered by a JavaScript call to the applet. Some clever hacks used to be posted on the Web, but they were rather cumbersome to implement and may no longer work on more modern browsers. You can also program the Java applet to fetch a text file after it starts up and then script the access of that value from JavaScript (as described in the following section). Signed scripts (Chapter 46) and applets can break through these security barriers after the user has given explicit permission to do so.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

1184 Part V . Putting JavaScript to Work (Web server info)

Tuesday, October 30th, 2007

1184 Part V . Putting JavaScript to Work Listing 44-3 (continued)

Select Time Zone:

Select Background Color: Select Color Text Color:

Select Font:
Select Font Style:
Select Font Size:



We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

1183Chapter 44 .Scripting Java Applets and Plug-ins The (Web hosting company)

Monday, October 29th, 2007

1183Chapter 44 .Scripting Java Applets and Plug-ins The methods shown in Listing 44-2 are defined specifically for scripted access. In this case, they safely stop the applet thread before changing any values. The last method is one I recommend to applet authors. The method returns a small bit of documentation containing information about the kind of methods that the applet likes to have scripted and what you can have as the passed parameter values. Now that you see the amount of scriptable information in this applet, look at Listing 44-3, which takes advantage of that scriptability by providing several HTML form elements as user controls for the clock. The results are shown in Figure 44-2. Listing 44-3: A More Fully Scripted Clock Clock with Lots o Widgets Continued
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

1182 Part V . (Remote web server) Putting JavaScript to Work

Monday, October 29th, 2007

1182 Part V . Putting JavaScript to Work have a number of methods defined that enable you to make scripted changes to variable values. To view a sample of an applet designed for scriptability, open the Java source code file for Listing 44-2 from the CD-ROM. A portion of that program listing is shown in the following example. Listing 44-2: Partial Listing for ScriptableClock.java /* Begin public methods for getting and setting data via LiveConnect */ public void setTimeZone(String zone) { stop(); timeZone = (zone.startsWith( GMT )) ? true : false; start(); } public void setFont(String newFont, String newStyle, String newSize) { stop(); if (newFont != null && newFont != ) fontName = newFont; if (newStyle != null && newStyle != ) setFontStyle(newStyle); if (newSize != null && newSize != ) setFontSize(newSize); displayFont = new Font(fontName, fontStyle, fontSize); start(); } public void setColor(String newbgColor, String newfgColor) { stop(); bgColor = parseColor(newbgColor); fgColor = parseColor(newfgColor); start(); } public String getInfo() { String result = Info about ScriptableClock.classrn ; result += Version/Date: 1.0d1/2 May 1996rn ; result += Author: Danny Goodman (dannyg@dannyg.com)rn ; result += Public Variables:rn ; result += (None)rnrn ; result += Public Methods:rn ; result += setTimeZone( GMT | Locale )rn ; result += setFont( fontName , Plain | Bold | Italic , fontSize )rn ; result += setColor( bgColorName , fgColorName )rn ; result += colors: Black, White, Red, Green, Blue, Yellowrn ; return result; } /* End public methods for scripted access. */
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

1181Chapter 44 .Scripting Java Applets and Plug-ins Accessing (Email web hosting)

Monday, October 29th, 2007

1181Chapter 44 .Scripting Java Applets and Plug-ins Accessing Java fields In a bit of confusing lingo, public variables and methods are often referred to as fields. These elements are not the kind of text entry fields that you see on the screen; rather, they re like slots (another term used in Java) where you can slip in your requests and data. Remember these terms, because they may appear from time to time in error messages as you begin scripting applets. Scripting Applets in Real Life Because the purpose of scripting an applet is to gain access to the inner sanctum of a compiled program, the program should be designed to handle such rummaging around by scripters. If you can t acquire a copy of the source code or don t have any other documentation about the scriptable parts of the applet, you may have a difficult time knowing what to script and how to do it. Although the applet s methods are reflected as properties in an applet object, writing a for…inloop to examine these methods tells you perhaps too much. Figure 44-1 shows a partial listing of such an examination of the ScriptableClock applet. This applet has only public methods (no variables), but the full listing shows the dozens of fields accessible in the applet. What you probably won t recog nize, unless you have programmed in Java, is that within the listing are dozens of fields belonging to the Java classes that automatically become a part of the applet during compilation. From this listing, you have no way to distinguish the fields defined or overridden in the applet code from the base Java fields. Figure 44-1: Partial listing of fields from ScriptableClock Getting to scriptable methods If you write your own applets or are fortunate enough to have the source code for an existing applet, the safest way to modify the applet variable settings or the running processes is through applet methods. Although setting a public variable value may enable you to make a desired change, you don t know how that change may impact other parts of the applet. An applet designed for scriptability should
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

1180 Part (Web host) V . Putting JavaScript to Work

Sunday, October 28th, 2007

1180 Part V . Putting JavaScript to Work Listing 44-1 shows how all this works with the tag for a scriptable digital clock applet example. The script includes calls to two of the applet s methods: to stop and to start the clock. Listing 44-1: Stopping and Starting an Applet A Script That Could Stop a Clock

Simple control over an applet


The syntax for accessing the method (in the two functions) is just like JavaScript in that the references to the applet s methods include the applet object (clock1 in the example), which is contained by the document object. Java applet properties The Java equivalents of JavaScript object properties are called public instance variables. These variables are akin to JavaScript global variables. If you have access to some Java source code, you can recognize a public instance variable by its public keyword: public String fontName Java authors must specify a variable s data type when declaring any variable. That s why the Stringdata type appears in the preceding example. Your scripts can access these variables with the same kind of syntax that you use to access JavaScript object properties. If the fontName variable in ScriptableClock.class had been defined as a public variable (it is not), you could access or set its value directly, as shown in the following example. var theFont = document.applets[0].fontName document.applets[0].fontName = Courier
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

1179Chapter 44 .Scripting Java Applets and Plug-ins A (Affordable web design)

Sunday, October 28th, 2007

1179Chapter 44 .Scripting Java Applets and Plug-ins A Little Java If you plan to look at a Java applet s scripted capabilities, you can t escape having to know a little about Java applets and some terminology. The discussion goes more deeply into object orientation than you have seen with JavaScript, but I ll try to be gentle. Java building blocks classes One part of Java that closely resembles JavaScript is that Java programming deals with objects, much the way JavaScript deals with a page s objects. Java objects, however, are not the familiar HTML objects but rather more basic building blocks, such as tools that draw to the screen and data streams. But both languages also have some non-HTML kinds of objects in common: strings, arrays, numbers, and so on. Every Java object is known as a class a term from the object-orientation world. When you use a Java compiler to generate an applet, that applet is also a class, which happens to incorporate many Java classes, such as strings, image areas, font objects, and the like. The applet file you see on the disk is called a class file, and its file extension is .class. This file is the one you specify for the CODE attribute of an tag. Java methods Most JavaScript objects have methods attached to them that define what actions the objects are capable of performing. A string object, for instance, has the toUpperCase() method that converts the string to all uppercase letters. Java classes also have methods. Many methods are predefined in the base Java classes embedded inside the virtual machine. But inside a Java applet, the author can write methods that either override the base method or deal exclusively with a new class created in the program. These methods are, in a way, like the functions you write in JavaScript for a page. Not all methods, however, are created the same. Java lets authors determine how visible a method is to outsiders. The types of methods that you, as a scripter, are interested in are the ones declared as public methods. You can access such methods from JavaScript via a syntax that falls very much in line with what you already know. For example, a common public method in applets stops an applet s main process. Such a Java method may look such as this: public void stop() { if(thread != null) { thread.stop(); thread = null; } } The void keyword simply means that this method does not return any values (compilers need to know this stuff). Assuming that you have one applet loaded in your page, the JavaScript call to this applet method is document.applets[0].stop()
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

1178 Part V . Putting JavaScript to Work (Web hosting billing)

Saturday, October 27th, 2007

1178 Part V . Putting JavaScript to Work Such a broad swath of browsers not supporting the feature (especially the IE for Macintosh, which has been factory-installed as the default browser on millions of Macs), makes it difficult to design a public Web application that relies on LiveConnect features. Design your pages accordingly. The internal mechanisms that allow scripts to communicate with applets and plug-ins are quite different for NN and IE. NN3 and NN4 relied exclusively on the Java virtual machine (JVM) that shipped with most OS platform versions of the browsers. In NN4+, the JVM doesn t load until it is needed, sometimes causing a brief delay in initial execution. For the most part, though, the underlying Java engine is invisible to the scripter (you) and certainly to the visitors of your sites. At most, visitors see statusbar messages about applets loading and running. IE/Windows, on the other hand, has its own internal architecture for communi cating between processes. To Windows, most processes are treated as components that have properties and methods accessible to other components. Whether you use the technology to communicate with a Java applet or an ActiveX control, the advantage to you as an author is that LiveConnect extends the document object model to include objects and data types that are not a part of the HTML world. HTML, for instance, does not have a form element that displays real- time stock ticker data; nor does HTML have the capability to treat a sound file like anything more than a URL to be handed off to a helper application. With LiveConnect, however, your scripts can treat the applet that displays the stock ticker as an object whose properties and methods can be modified after the applet loads; scripts can also tell the sound when to play or pause by controlling the plug- in that manages the incoming sound file. Why Control Java Applets? A question I often hear from experienced Java programmers is, Why bother con trolling an applet via a script when you can build all the interactivity you want into the applet itself? This question is valid if you come from the Java world, but it takes a viewpoint from the HTML and scripting world to fully answer it. Java applets exist in their own private rectangles, remaining largely oblivious to the HTML surroundings on the page. Applet designers who don t have extensive Web page experience tend to regard their applets as the center of the universe rather than as components of HTML pages. As a scripter, on the other hand, you may want to use those applets as powerful components to spiff up the overall presentation. Using applets as prewritten objects enables you to make simple changes to the HTML pages including the geographic layout of elements and images at the last minute, without having to rewrite and recompile Java program code. If you want to update the look with an entirely new graphical navigation or control bar, you can do it directly via HTML and scripting. When it comes to designing or selecting applets for inclusion into my scripted page, I prefer using applet interfaces that confine themselves to data display, putting any control of the data into the hands of the script, rather than using onscreen buttons in the applet rectangle. I believe this setup enables much greater last-minute flexibility in the page design not to mention consistency with HTML form element interfaces than putting everything inside the applet rectangle.
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.