spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

Developer News
Metasploit 3.2 Offers More 'Evil Deeds'
'Thank You Apple. Seriously.'
The Buzz: BlackBerry App Store Seen Next

JavaScript Tip of the Week for December 2, 1996: LiveConnect: The Adventure Continues


All of the examples use the dynamicText applet, written by yours truly, to be displayed. But, everything else is done in JavaScript. The scrolling of the text, the fading of the letters, the sizing of the fonts; all done in JavaScript. With LiveConnect, you don't even have to know Java to use it effectively and uniquely . Since I'm not in the business of giving Java tips, I'm just going to give you the source; straight. But, I will explain how the JavaScript side of it works, and how to use it. The point of this tip is not so much to show you how to use the dynamicText applet, but more to show you how Java and JavaScript can coexist. Making both programmer's and designer's lives easier. Think of it as an extenstion of the language.

To show you how easy it is, I've embedded dynamicText in this page, and connected it to JavaScript using a simple form. Enter some text, then press setText.
Not quite as exciting as the other three examples. The point is, however, that this can be made very simple or very elaborate. Let's learn how to do it. The first step in adding dynamicText, or any Java app to your site, is to embed it with the APPLET tag.
    <APPLET NAME = "dynamictextApp" CODE = "dynamictext.class" WIDTH = 200 HEIGHT = 25>
    <PARAM NAME = "x_pos" VALUE = "2">
    <PARAM NAME = "y_pos" VALUE = "15"> 
    <PARAM NAME = "center" VALUE = "0"> 
    <PARAM NAME = "fontface" VALUE = "TimesRoman">
    <PARAM NAME = "fontsize" VALUE = "16">
    <PARAM NAME = "fontcolor" VALUE = "0,0,0"> 
    <PARAM NAME = "bgcolor" VALUE = "255,255,255">
    </APPLET>
The name of the dynamicText class file, while contains the compiled Java code, is "dynamictext.class". The dynamicText app has eight initial parameters; all must be included for it to work. The first two, "x_pos" and "y_pos" control the placement of the text (in pixels) in relation to the upper left hand corner of the applet. The next, "center", determines if the text will be centered. Setting this to "1" will center the text, anything else will just be ignored.

The next three; "fontface", "fontsize", and "fontcolor", speak for themselves. The only thing that you should note is that the color of the font is done in RGB, as opposed the hex (00, FF etc.). The values for each color, which are between 0 and 255, must be in this form: "rrr, ggg, bbb". For instance, if I want straight blue text, I'd use this RGB color in the "fontcolor" parameter : "0,0,255". The same rule applies to the "bgcolor" parameter, which controls the color of the applet's background.

Now on to the fun part: controlling the applet throught JavaScript. Referring to an applet in JavaScript is very easy, just use its name (The name paramter in the APPLET tag specifies the name). In this case, I can referr to the dynamicText applet like this: "document.dynamictextApp". The dynamicText applet has a group of Methods, which are very similar to functions, that allow JavaScript to control what's happening in the applet. The first and foremost is the setText() Method, which allows you to change the text that the applet is displaying. To do this, simply pass setText() a string of text:
    document.dynamictextApp.setText("Some Text");
This would display "Some Text" in the dynamicText applet window. There are a number of other things that can be changed on the fly using JavaScript, and here they are:

Font Size: must be an integer. This would be size 12 pt:
    document.dynamictextApp.setfSize(12);
Font Color: must be in the RGB format. This would be red:
    document.dynamictextApp.setfColor("255,0,0");
Height and Width positioning: This would be 10 pixels down, 10 pixels over left:
    document.dynamictextApp.setXY(10,10);
In the future, you will see more options, but for now I'm sure these will suffice. How about a few more for practice? Let's make the font color a light grey, change the font size to 24, and make the text say, "I am the text.":
    document.dynamictextApp.setfColor("190,190,190");
    document.dynamictextApp.setfSize(24);
    document.dynamictextApp.setText("I am the text.");
Alone this may seem only slightly interesting, but I used these same functions (or Methods) to do all those whiz-bang examples. To find out how I did it and how you can too, read on to part 2.

Source



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview · Controllers: Programming Application Logic - Part 2 · How to Use JavaScript to Validate Form Data
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Choosing the Right Online Backup Provider · Mother Avaya Nurtures Her Technology Partners · Software as a Service a Winning Model for Hotspot Provider