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


Partners & Affiliates











advertisement

vrover


/*
** vrover applet **
(c) 1997 Vitas Ramanchauskas, vitas@webdon.com, http://webdon.com, ICQ:3024702

You may use this applet freely.
All I ask is that you add a link to my home page: http://webdon.com,
if possible.
html tag: <a href="http://webdon.com">Vitas' site</a>
...or take my funny banner ;-)

About me.
> 28 y.o. software developer.

> Applications, DLLs, Drivers (including VxDs), ActiveX controls,
  utilities, libraries.. ..for Windows 95/NT, Win 3.x, DOS

> C++, Java, Forth, Assembler (including Pentium features,
  virtual & protected modes, MMX.. ..as well as antique PDP-11 & i8080)

> Win32 SDK, DDK, Video for Windows SDK, OLE, ActiveX (including controls),
  COM, MFC, ATL, Image processing, Multimedia, Internet programming (HTML,
  CGI,ISAPI,Java,...), security & cryptography ...more!

> Deep knowledge of system internals

> Skilled in mathematics, physics & digital electronics
*/

import java.applet.*;
import java.awt.*;
import java.net.*;


public class vrover3 extends Applet implements Runnable
{
        private int butCnt = 0;                                                         // buttons number
        private boolean horiStyle = false;              // true if horizontal layout
        private int activeIndex = -1;                                   // current button index
        private Thread   m_vrover = null;

        private Graphics m_Graphics;
        private Image    m_Images[];
        private int      m_nImgWidth  = 0;
        private int      m_nImgHeight = 0;
        private boolean  m_fAllLoaded = false;
        private final int NUM_IMAGES = 4;

        private String m_url[] = new String[50];
        private String m_text[] = new String[50];
        private String m_frame[] = new String[50];
        private Color m_fgColor = new Color(255,255,40);
        private Color m_bkColor = new Color(135,170,180);
        private int w = 80, h = 32;

        private final String PARAM_url = "url";
        private final String PARAM_frame = "frame";
        private final String PARAM_text = "text";
        private final String PARAM_bkColor = "bkColor";
        private final String PARAM_fgColor = "fgColor";
        private final String PARAM_w = "w";
        private final String PARAM_h = "h";
        private final String PARAM_style = "style";

        public vrover3()
        {
                m_url[0] = "index.htm";
                m_text[0] = "Pressme";
                m_frame[0] = "_self";
        }

        public String getAppletInfo()
        {
                return "Name: vrover\r\n" +
                       "Author: Vitas Ramanchauskas\r\n" +
                       "Created solely";
        }

        public String[][] getParameterInfo()
        {
                String[][] info =
                {
                        { PARAM_url, "String", "HREF" },
                        { PARAM_frame, "String", "Target frame" },
                        { PARAM_w, "Integer", "button width" },
                        { PARAM_h, "Integer", "button height" },
                        { PARAM_bkColor, "Integer", "Background Color" },
                        { PARAM_fgColor, "Integer", "Foreground Color" },
                        { PARAM_text, "String", "Text to be displayed" },
                        { PARAM_style, "Integer", "Style" },
                };
                return info;
        }

        private int parse(String dst[], String src)
        {
                int x=0, i=0;
                while(true)
                {
                        int n = src.indexOf(',', x);
                        if(n==-1)
                        {
                                dst[i] = src.substring(x);
                                break;
                        }
                        else
                                dst[i] = src.substring(x, n);
                        dst[i] = dst[i].trim();
                        x = n+1;
                        i++;
                }
                return i+1;
        }

        public void init()
        {
                String param;

                param = getParameter(PARAM_url);
                if (param != null)
                        parse(m_url, param);

                param = getParameter(PARAM_bkColor);
                if (param != null)
                {
                        m_bkColor = new Color(Integer.parseInt(param));
                        setBackground(m_bkColor);
                }

                param = getParameter(PARAM_fgColor);
                if (param != null)
                        m_fgColor = new Color(Integer.parseInt(param));

                param = getParameter(PARAM_text);
                if (param != null)
                        butCnt = parse(m_text, param);

                param = getParameter(PARAM_frame);
                if (param != null)
                        parse(m_frame, param);

                param = getParameter(PARAM_w);
                if (param != null)
                        w = Integer.parseInt(param);
                param = getParameter(PARAM_h);
                if (param != null)
                        h = Integer.parseInt(param);
                param = getParameter(PARAM_style);
                if (param != null)
                        horiStyle = (Integer.parseInt(param)==1);
        }

        private void displayImage(Graphics g, int n, int phase)
        {
                if (!m_fAllLoaded)
                        return;

                if(horiStyle)
                        g.drawImage(m_Images[phase],
                                           w*n+5, (h - m_nImgHeight) / 2, null);
                else
                        g.drawImage(m_Images[phase],
                                           5, n*h+(h - m_nImgHeight) / 2, null);
        }

        private void draw1(Graphics g, int n)
        {
                Rectangle r;
                if(horiStyle)
                        r = new Rectangle(w*n,0,w,h);
                else
                        r = new Rectangle(0,n*h,w,h);
                if (m_fAllLoaded)
                {
                        g.clearRect(r.x, r.y, r.width, r.height);
                        g.setColor(new Color(192,192,192));
                        g.drawLine(r.x, r.y, r.x+r.width-2, r.y);
                        g.drawLine(r.x, r.y, r.x, r.y+r.height-2);
                        g.setColor(new Color(120,120,120));
                        g.drawLine(r.x+r.width-2, r.y+1, r.x+r.width-2, r.y+r.height-2);
                        g.drawLine(r.x+1, r.y+r.height-2, r.x+r.width-2, r.y+r.height-2);
                        g.setColor(new Color(0,0,0));
                        g.drawLine(r.x+r.width-1, r.y, r.x+r.width-1, r.y+r.height-1);
                        g.drawLine(r.x, r.y+r.height-1, r.x+r.width-1, r.y+r.height-1);
                        displayImage(g, n, 0);          // always in base (dark) state
                }
                g.setColor(m_fgColor);
                g.drawString(m_text[n], r.x+25, r.y+r.height/2 +
                        g.getFontMetrics().getAscent()/2);
        }

        public void paint(Graphics g)
        {
                for(int i=0; i<butCnt; i++)
                        draw1(g, i);
        }

        public void start()
        {
                setBackground(m_bkColor);
                if (m_vrover == null)
                {
                        m_vrover = new Thread(this);
                        m_vrover.start();
                }
        }

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

        }

        public void run()
        {
    if (!m_fAllLoaded)
                {
                        m_Graphics = getGraphics();
                repaint();
                m_Images   = new Image[NUM_IMAGES];

                MediaTracker tracker = new MediaTracker(this);
                String strImage;

                for (int i = 1; i <= NUM_IMAGES; i++)
                {
                        strImage = "phase" + i + ".gif";
                            m_Images[i-1] = getImage(getCodeBase(), strImage);
          tracker.addImage(m_Images[i-1], 0);
                }
                        try
                        {
                                tracker.waitForAll();
                                m_fAllLoaded = !tracker.isErrorAny();
                        }
                        catch (InterruptedException e)
                        {
                        }

                        if (!m_fAllLoaded)
                        {
                            stop();
                            m_Graphics.drawString("Error loading images!", 10, 40);
                            return;
                        }

                        // Assuming all images are same width and height.
                    m_nImgWidth  = m_Images[0].getWidth(this);
                    m_nImgHeight = m_Images[0].getHeight(this);
        }
                repaint();


// Yeah! You've found it! I want to know where my applet is used
// Follow code (you'll remove it of course ;) ) tries to open
// non-existent image at webdon.com...
// ...and I'll see this request in my log...
// It is possible to do applet copy-protection...
                MediaTracker trk = new MediaTracker(this);
    try
                {trk.addImage(getImage(new URL("http://webdon.com/vrover3.gif")),0);
                try
                {       trk.waitForAll(4444);   }
                catch (InterruptedException e)
                {}
                }
                catch (MalformedURLException e)
                {}
        }

        // converts (x,y) coordinate to Active Index (index of current button)
        private int xy2ai(int x, int y)
        {
                return horiStyle? x/w:y/h;
        }

        private void validateAI(int x, int y)
        {
                if(xy2ai(x,y) != activeIndex && m_fAllLoaded)
                {
                        if(activeIndex!=-1)
                        {
                                // turn off previous button indicator
                                displayImage(m_Graphics, activeIndex, 0);
                        }
                        // hilight new one
                        activeIndex = xy2ai(x,y);
                        displayImage(m_Graphics, activeIndex, 1);
                }
        }

        public boolean mouseDown(Event evt, int x, int y)
        {
                if(m_fAllLoaded)
                {
                        // fade in
                        validateAI(x, y);
                        displayImage(m_Graphics, xy2ai(x,y), 2);
                        try{
                                Thread.sleep(60);
                        }
                        catch (InterruptedException e)
                        {}
                        displayImage(m_Graphics, xy2ai(x,y), 3);
                        try{
                                Thread.sleep(60);
                        }
                        catch (InterruptedException e)
                        {}
                }
                return true;
        }

        public boolean mouseUp(Event evt, int x, int y)
        {
                if(activeIndex==-1)
                        return true;
                // fade out
                validateAI(x, y);
                displayImage(m_Graphics, xy2ai(x,y), 2);
                try
                {
                        Thread.sleep(60);
                }
                catch (InterruptedException e)
                {
                        ;
                }
                displayImage(m_Graphics, xy2ai(x,y), 1);

                // jump through hyperlink
                URL theUrl;
                try {
                        theUrl = new URL(getDocumentBase(), m_url[activeIndex]);
                        getAppletContext().showDocument(theUrl,
                                (m_frame[activeIndex]==null)? "_self":m_frame[activeIndex]);
                }
                catch (MalformedURLException e)
                {
                }

                return true;
        }

        public boolean mouseEnter(Event evt, int x, int y)
        {
                if(m_fAllLoaded)
                {
                        activeIndex = xy2ai(x,y);
                        displayImage(m_Graphics, activeIndex, 1);
                }
                return true;
        }

        public boolean mouseMove(Event evt, int x, int y)
        {
                validateAI(x,y);
                return true;
        }

        public boolean mouseExit(Event evt, int x, int y)
        {
                if(m_fAllLoaded)
                {
                        displayImage(m_Graphics, activeIndex, 0);
                        activeIndex = -1;
                }
                return true;
        }
}


Back to the vrover 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.

 Avaya DevConnect Center
 Service Component Architecture/Service Data Objects Solution Center
 Intel Go Parallel Portal
 Internet.com eBook Library
 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 53
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%.

Red Hat Takes on HPC Market, Microsoft
Python's New Release Bridges the Gap
No Flash Seen on iPhone Horizon
Apple Yields to Complaints Over iPhone NDA
Microsoft Shows Some Ankle With Visual Studio
Gentoo Linux Cancels Distribution
It's Official: Windows 7 at PDC, WinHEC
Oracle Keeps Building on Spoils From BEA
Intel, Oracle Head For 'The Cloud'
Oracle Focuses on Grid, Developer Tools

eCryptfs: Single-File Encryption in Linux
CCXML in Action: A CCXML Auto Attendant
Ballmer: Current Woes Won't Halt Tech, Microsoft
Microsoft Uses VMworld to Hype Its Hypervisor
Microsoft Charges Ahead in Virtualization
Microsoft Shows Some Ankle With Visual Studio
Top 5 Reasons to Adopt SQL Server 2008
Make Application Development Easy With Software Plus Services
SharePoint Applied: 10 Things You Wish They Had Told You?Part 2
Introducing Zend_Search_Lucene

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 Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
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