advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement


Reviews : Java Books :
Beginning Java 2- JDK 1.3 Version : Images and Animation

Buy this book
Title: Beginning Java 2- JDK 1.3 Version
ISBN: 1861003668
US Price: $ 49.99
Canadian Price:
C$ 74.95
UK Price: £ 35.99
Publication Date: March 2000
Pages: 1230
© Wrox Press Limited, US and UK.

Beginning Java 2- JDK 1.3 Version
Images and Animation

Initializing the Applet

In the init() method we will need to create the ClockFace object and the Hands object that will make up the clock. We just have to decide how the hands are going to overlay the clock face.

Back in Chapter 12 we saw how a JFrame object had several window panes, including a content pane, to which you typically add the components you want to display, plus a glass pane that overlays the content pane. An object of type JApplet has exactly the same pane structure. We can add an object of type ClockFace to the content pane for the applet, and make the Hands object the glass pane. As long as it's transparent, the content pane with its ClockFace component will be visible underneath the glass pane – which will be our Hands object. In fact in general, a glass pane can be any object of a class that has as a superclass. To replace the default glass pane with your component, you just call the setGlassPane() method for the applet object with a reference to your component as the argument. Here's the code for the init() method that will set our clock up like that:

public void init()
{
  Dimension size = getSize(); // Get the applet size

  // Create the clockface to fit within the applet
  int clockDiameter = Math.min(size.width, size.height)*9/10;
  clock = new ClockFace(clockDiameter);
  getContentPane().add(clock);  // Add clockface to content pane

  hands = new Hands(clockDiameter); // Create the hands panel
  setGlassPane(hands);  // Make the hands the glass pane                  
  hands.setVisible(true);  // Set glass pane visible
}

We get the size of the applet by calling getSize(), and use that to decide the diameter of the clock. Ninety percent of the smaller of the width and height of the applet is a suitable choice to make it fit comfortably. Once we have created the ClockFace object, we just add it to the content pane for the applet. We then create the Hands object and pass it to setGlassPane() to make it the glass pane for the applet. Note that we must call setVisible() for the glass pane because it will be set as invisible by default.

That's all that's necessary to create the visual appearance of the clock. We just need to set it going somewhere, and that's the job of the start() method for the applet object.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs