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


Partners & Affiliates











advertisement

TinyScroller


import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class tinyScroller extends Applet
    implements Runnable {                // Threaded application

    int maxLines=100,                    // Added by a user
    direction=0,                         // 0=up, 1=down
    delay=100,                           // delay, controls scroll speed
    spacing=12,                          // spacing, between lines
    XPos=5,                              // XPos, indent
    maxLine=0,                           // maxLine, # of Lines being sent
    current,                             // current, initial position
    height;                              // height, of the applet

    String[] Line = new String[maxLines];// Lines, to be displayed, 12 max

    Image offImage, bg;                  // Double buffering to eliminate
    Graphics offGrfx;                    // frame flicker

    Font outFont;                        // Output font (if passed)
    boolean customFont = false;          // Flag, is there a custom outFont?

    Color background, fontColor;

    Thread runner;

    public void init() {

        /****  Get attributes, if available  ****/
        String bgRed$      = getParameter("BGRED");
        String bgGreen$    = getParameter("BGGREEN");
        String bgBlue$     = getParameter("BGBLUE");
        String fgRed$      = getParameter("FGRED");
        String fgGreen$    = getParameter("FGGREEN");
        String fgBlue$     = getParameter("FGBLUE");
        String spacing$    = getParameter("SPACING");
        String delay$      = getParameter("DELAY");
        String XPos$       = getParameter("XPOS");
        String maxLine$    = getParameter("MAXLINE");
        String background$ = getParameter("BACKGROUND");
        String fontName$   = getParameter("FONTNAME");
        String fontSize$   = getParameter("FONTSIZE");
        String direction$  = getParameter("DIRECTION");

        /****           Data lines           ****/
        for (int x=0; x<maxLines; x++) {
            Line[x] = getParameter("LINE" + Integer.toString(x+1));
        }

        /****          Setting Font          ****/
        if ((fontSize$ != null) && (fontName$ != null)) {
            int size = Integer.parseInt(fontSize$);
            outFont = new Font(fontName$, Font.PLAIN, size);
            customFont = true;
        }

        /****          Find maxline         ****/
        for (int x=0; x<maxLines; x++) {
            if (Line[x] == null) break;
            maxLine++;
        }

        /****      Convert color values     ****/
        int Red=255;
        if (bgRed$ != null)
	  Red = Integer.parseInt(bgRed$);

        int Green=255;
        if (bgGreen$ != null)
	  Green = Integer.parseInt(bgGreen$);

        int Blue=255;
        if (bgBlue$ != null)
	  Blue = Integer.parseInt(bgBlue$);

        int fRed=0;
        if (fgRed$ != null)
          fRed = Integer.parseInt(fgRed$);

        int fGreen=0;
        if (fgGreen$ != null)
          fGreen = Integer.parseInt(fgGreen$);

        int fBlue=0;
        if (fgBlue$ != null)
          fBlue = Integer.parseInt(fgBlue$);

        /****   Convert attribute values   ****/
        if (spacing$ != null)
	  spacing = Integer.parseInt(spacing$);

        if (delay$ != null)
	  delay = Integer.parseInt(delay$);

        if (XPos$ != null)
	  XPos = Integer.parseInt(XPos$);

        height = size().height;

        if (direction$ != null)
          direction = Integer.parseInt(direction$);

        if (background$ !=null)
          bg = getImage(getDocumentBase(), background$);

        /****        Set init index       ****/
        if (direction == 0) {
          current = height;
        }
        else {
          current = -(maxLine * spacing);
        }

        /****     Set foreground color    ****/
        fontColor = new Color(fRed, fGreen, fBlue);

        /****     Set background color    ****/
        background = new Color(Red, Green, Blue);
        setBackground(background);


        /****         Init buffer         ****/
        offImage = createImage(size().width, size().height);
        offGrfx = offImage.getGraphics();

    }

    public void paint(Graphics screen) {

        /****     Clear prev image        ****/
          offGrfx.setColor(background);
          offGrfx.fillRect(0,0,size().width, size().height);

        /****      Draw background        ****/
          if (bg != null)
            offGrfx.drawImage(bg, 0, current - height, null);

        /****      Set custom font        ****/
          offGrfx.setColor(fontColor);
          try { offGrfx.setFont(outFont); }
          catch (NullPointerException e) {}

        /****        Draw lines           ****/
          if (direction == 0) {
              for (int i=0; i<maxLine; i++)
                  offGrfx.drawString(Line[i],  XPos, current + (i * spacing));
          }
          else {
              for (int i=0; i<maxLine; i++)
                  offGrfx.drawString(Line[i],  XPos, current + ( (maxLine-i) * spacing));
          }

        /****   Flip buffer to screen     ****/
          screen.drawImage(offImage, 0, 0, this);
    }

    public void update(Graphics screen) {

        /****      Override update        ****/
          paint(screen);
    }

    public void start() {
        if (runner == null) {
            runner = new Thread(this);
            runner.start();
        }
    }

    public void run() {
        while (true) {
            repaint();
            if (direction == 0) {
                current--;
                if ((current + (maxLine * spacing)) < 0)
                current = height + spacing;
            }
            else {
                current++;
                if (current > height)
                current = -(maxLine * spacing);
            }
            try { Thread.sleep(delay); }
            catch (InterruptedException e) { }
        }
    }

    public void stop() {
        if (runner != null) {
            runner.stop();
            runner = null;
        }
    }
}


Back to the TinyScroller applet page.

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 RIA Development Center
 IBM Rational Resource Center
 Destination .NET
XML error: not well-formed (invalid token) at line 33
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%.

Free VMware Server 2.0 Now Release Candidate
Linux Player Xandros Grabs Storied Rival Linspire
Hey Enterprise: Here Comes the 3G iPhone
MySpace Opens Profile Portability API
Microsoft Jumps Into Virtualization Fray
Eclipse Ganymede Makes It Easier for Devs
Open Source Nokia a Threat to Microsoft, Google?
Salesforce, Google Head for 2nd on Apps
HP Open Sources Unix File System for Linux
Red Hat Opens Its Network to Space

Build a Generic Histogram Generator for SQL Server
Beyond XML and JSON: YAML for Java Developers
Mastering the Windows Mobile Emulators
Avaya AE Services Provide Rapid Telephony Integration with Facebook
Featured Algorithm: Intel Threading Building Blocks: parallel_reduce
Getting Started with Windows Live Admin Center
Eight Key Practices for ASP.NET Deployment
Java ME User Interfaces: Do It with LWUIT!
Talking VPro: Transcript
Bringing Semantic Technology to the Enterprise

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



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 eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES