Solved

Data in Ticker class

Posted on 2002-07-02
4
389 Views
Last Modified: 2013-12-25
Go to http://www.nseindia.com

On the Right-Top corner you will find 2 lines (similar to Marquee in HTML). If you move your mouse over it it will stop. If you drag it to the right side it will start scrolling right & if you drag it to your left it will start scrolling to your left.

I checked the source code and found that an applet has been used to do this. I was told that the values are read from a text file(formed from database)....

How can i generate this Ticker class with my data !!
0
Comment
Question by:viswa20
  • 2
4 Comments
 
LVL 11

Expert Comment

by:mouatts
Comment Utility
In short you can't.

The source of the data is held within the applet code and so far as I can tell you can't get to it to change it.

There are, however loads of tickers available for free that will allow you to do this. Try a search on yahoo for 'free java applets' or something similar or try http://www.gamelan.com

Steve
0
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
Here is the .java file for tickler.class;

// FrontEnd Plus GUI for JAD
// DeCompiled : Ticker.class

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.URL;
import java.util.Hashtable;
import java.util.Properties;

public class Ticker extends Applet
    implements Runnable, MouseListener, MouseMotionListener
{

    String tickerData[];
    String tmpTickerData[];
    String typeOfData;
    String tod;
    String border;
    String upImg;
    String downImg;
    Thread scroller;
    int w;
    int h;
    int X;
    boolean scroll;
    boolean doSetType;
    int scrollDelay;
    int fetchDelay;
    Color backColor;
    Color borderColor;
    Color fontColor;
    Graphics offg;
    Graphics offg2;
    Image offimg;
    Image offimg2;
    Image upArrow;
    Image downArrow;
    MediaTracker tracker;
    Font font;
    Font bfont;
    FontMetrics fm;
    FontMetrics bfm;
    boolean mouseIn;
    boolean mousePressed;
    int mouseUpX;
    int mouseDownX;
    int mouseHoverX;
    int len;
    int d;
    int td;
    int textY;
    int imageY;
    int imgH;
    int imgW;
    int xGap;
    int xInc;
    int xDiff;
    int currX;
    int prevX;
    int fetchDelayCount;
    int fetchDelayCountMax;
    Cursor cur1;
    Cursor cur2;
    boolean fromNse;

    public Ticker()
    {
        fromNse = false;
    }

    public void init()
    {
        URL url = getDocumentBase();
        String s = "www.nseindia.com";
        String s1 = "www.nse-india.com";
        String s2 = "147.208.181.7";
        String s3 = "147.208.181.8";
        String s4 = url.getHost();
        if(s4.equals(s) || s4.equals(s1) || s4.equals(s2) || s4.equals(s3))
            fromNse = true;
        else
            fromNse = false;
        backColor = new Color(getInt(getParameter("bgcolor"), 16, 0));
        setBackground(backColor);
        border = getParameter("border");
        if(border == null)
            border = "no";
        borderColor = new Color(getInt(getParameter("border_color"), 16, 0));
        fontColor = new Color(getInt(getParameter("font_color"), 16, 0));
        String s5 = getParameter("ticker_font");
        if(s5 == null)
            s5 = "SansSerif";
        int i = getInt(getParameter("font_size"), 10, 8);
        font = new Font(s5, 0, i);
        bfont = new Font(s5, 1, i);
        fm = getFontMetrics(font);
        bfm = getFontMetrics(bfont);
        scroll = false;
        xInc = -1;
        xGap = 25;
        cur1 = new Cursor(12);
        cur2 = new Cursor(0);
        scrollDelay = getInt(getParameter("scroll_delay"), 10, 10);
        fetchDelay = getInt(getParameter("fetch_delay"), 10, 1000);
        fetchDelayCount = 0;
        fetchDelayCountMax = fetchDelay / scrollDelay;
        typeOfData = getParameter("type");
        upImg = getParameter("upArrow");
        downImg = getParameter("downArrow");
        upArrow = getImage(getDocumentBase(), upImg);
        downArrow = getImage(getDocumentBase(), downImg);
        tracker = new MediaTracker(this);
        tracker.addImage(upArrow, 0);
        tracker.addImage(downArrow, 0);
        w = -1;
        h = -1;
        String s6 = "";
        String s7 = "";
        boolean flag = true;
        s6 = getParameter("ticker_width");
        if(s6 == null || s6.trim().equals(""))
            flag = false;
        s7 = getParameter("ticker_height");
        if(s7 == null || s7.trim().equals(""))
            flag = false;
        try
        {
            if(flag)
            {
                w = Integer.parseInt(s6, 10);
                h = Integer.parseInt(s7, 10);
            } else
            {
                w = getWidth();
                h = getHeight();
            }
        }
        catch(Exception exception)
        {
            w = getWidth();
            h = getHeight();
        }
        X = xGap;
        offimg = createImage(w, h);
        offg = offimg.getGraphics();
        offg.clipRect(0, 0, w, h);
        offimg2 = createImage(w, h);
        offg2 = offimg2.getGraphics();
        offg2.clipRect(0, 0, w, h);
        addMouseListener(this);
        addMouseMotionListener(this);
        System.gc();
        tickerData = getData(typeOfData);
        tmpTickerData = tickerData;
        if(scroller == null)
        {
            scroller = new Thread(this);
            scroller.start();
            scroll = true;
        }
    }

    private void setType(String s)
    {
        typeOfData = s;
        tickerData = getData(typeOfData);
        X = xGap;
        doSetType = false;
    }

    public synchronized void callSetType(String s)
    {
        tod = s;
        doSetType = true;
    }

    public void update(Graphics g)
    {
        paint(g);
    }

    public void paint(Graphics g)
    {
        if(fromNse)
        {
            g.drawImage(offimg, 0, 0, this);
        } else
        {
            g.setFont(bfont);
            g.drawString("National Stock Exchange of India Limited", 10, 15);
        }
    }

    public void start()
    {
    }

    public void run()
    {
        try
        {
            try
            {
                tracker.waitForAll();
            }
            catch(InterruptedException interruptedexception)
            {
                return;
            }
            imgW = upArrow.getWidth(this);
            imgH = upArrow.getHeight(this);
            textY = (h - fm.getHeight()) + fm.getDescent();
            imageY = (h - imgH) / 2 - 2;
            scroller.setPriority(1);
            while(scroll && fromNse)
            {
                if(doSetType)
                    setType(tod);
                len = tickerData.length;
                if(!mouseIn)
                {
                    X += xInc;
                    move(X);
                    repaint();
                    try
                    {
                        Ticker _tmp = this;
                        Thread.sleep(scrollDelay);
                    }
                    catch(InterruptedException interruptedexception1) { }
                    fetchDelayCount++;
                    if(fetchDelayCount >= fetchDelayCountMax)
                    {
                        fetchDelayCount = 0;
                        System.out.println("X is : " + X);
                        X = xGap;
                        try
                        {
                            tmpTickerData = getData(typeOfData);
                        }
                        catch(Exception exception)
                        {
                            System.out.println("Exception caught while getting data : " + exception);
                        }
                        if(!tickerData.equals(tmpTickerData))
                            tickerData = tmpTickerData;
                    }
                }
            }
        }
        catch(Exception exception1)
        {
            System.out.println("Exception caught in run : " + exception1);
        }
    }

    private void move(int i)
    {
        offg2.setColor(backColor);
        offg2.fillRect(0, 0, w, h);
        td = 0;
        int j = i;
        boolean flag = false;
        do
        {
            if(j > w)
                break;
            char c = tickerData[td].charAt(0);
            String s = tickerData[td];
            if(c == '+' || c == '-')
                s = s.substring(1);
            int i1 = s.indexOf("<b>");
            int k;
            if(i1 != -1)
            {
                String s2 = s.substring(0, i1);
                String s4 = s.substring(i1 + 3, s.indexOf("</b>")) + " ";
                int k1 = fm.stringWidth(s2);
                if(j + k1 > 0)
                {
                    offg2.setColor(fontColor);
                    offg2.setFont(font);
                    offg2.drawString(s2, j, textY);
                }
                j += k1;
                int i2 = bfm.stringWidth(s4);
                if(j + i2 > 0)
                {
                    offg2.setColor(fontColor);
                    offg2.setFont(bfont);
                    offg2.drawString(s4, j, textY);
                }
                k = j + i2;
            } else
            {
                offg2.setColor(fontColor);
                offg2.setFont(font);
                offg2.drawString(s, j, textY);
                k = j + fm.stringWidth(s);
            }
            if(k + imgW > 0)
                if(c == '+')
                    offg2.drawImage(upArrow, k, imageY, this);
                else
                if(c == '-')
                    offg2.drawImage(downArrow, k, imageY, this);
            j = k + xGap;
            td++;
            if(td == len)
                td = 0;
        } while(true);
        td = len - 1;
        j = i - xGap;
        do
        {
            if(j < 0)
                break;
            char c1 = tickerData[td].charAt(0);
            String s1 = tickerData[td];
            if(c1 == '+' || c1 == '-')
                s1 = s1.substring(1);
            td--;
            if(td == -1)
                td = len - 1;
            int j1 = s1.indexOf("<b>");
            int l;
            if(j1 != -1)
            {
                String s3 = s1.substring(0, j1);
                String s5 = s1.substring(j1 + 3, s1.indexOf("</b>")) + " ";
                int l1 = bfm.stringWidth(s5);
                j = j - l1 - imgW - 1;
                if(j < w)
                {
                    offg2.setColor(fontColor);
                    offg2.setFont(bfont);
                    offg2.drawString(s5, j, textY);
                }
                l = j + l1;
                int j2 = fm.stringWidth(s3);
                j -= j2;
                if(j < w)
                {
                    offg2.setColor(fontColor);
                    offg2.setFont(font);
                    offg2.drawString(s3, j, textY);
                }
                j -= xGap;
            } else
            {
                j = j - fm.stringWidth(s1) - imgW - 1;
                offg2.drawString(s1, j, textY);
                l = j + fm.stringWidth(s1);
            }
            if(c1 == '+')
                offg2.drawImage(upArrow, l, imageY, this);
            else
            if(c1 == '-')
                offg2.drawImage(downArrow, l, imageY, this);
        } while(true);
        if(border.equals("yes"))
        {
            offg2.setColor(borderColor);
            offg2.drawRect(0, 0, w - 1, h - 1);
        }
        offg.drawImage(offimg2, 0, 0, null);
    }

    public void destroy()
    {
        scroller = null;
        scroll = false;
    }

    public int getInt(String s, int i, int j)
    {
        int k = 0;
        try
        {
            k = Integer.parseInt(s, i);
        }
        catch(Exception exception)
        {
            k = j;
        }
        return k;
    }

    private String[] getData(String s)
    {
        try
        {
            URL url = new URL(getCodeBase(), "/TickerFeed");
            HttpMessage httpmessage = new HttpMessage(url);
            Properties properties = new Properties();
            properties.put("type", s);
            InputStream inputstream = httpmessage.sendGetMessage(properties);
            ObjectInputStream objectinputstream = new ObjectInputStream(inputstream);
            Object obj = objectinputstream.readObject();
            String as[] = (String[])obj;
            inputstream.close();
            objectinputstream.close();
            return as;
        }
        catch(Exception exception)
        {
            System.out.println("Exception caught in getData : " + exception);
        }
        return null;
    }

    public void mouseEntered(MouseEvent mouseevent)
    {
        mouseIn = true;
        setCursor(cur1);
    }

    public void mouseExited(MouseEvent mouseevent)
    {
        mouseIn = false;
        setCursor(cur2);
    }

    public void mouseDragged(MouseEvent mouseevent)
    {
        try
        {
            prevX = currX;
            currX = mouseevent.getX();
            X = currX + xDiff;
            move(X);
            repaint();
        }
        catch(Exception exception) { }
    }

    public void mouseMoved(MouseEvent mouseevent)
    {
        mouseHoverX = mouseevent.getX();
    }

    public void mouseClicked(MouseEvent mouseevent)
    {
    }

    public void mousePressed(MouseEvent mouseevent)
    {
        mousePressed = true;
        mouseDownX = mouseevent.getX();
        xDiff = X - mouseDownX;
    }

    public void mouseReleased(MouseEvent mouseevent)
    {
        mousePressed = false;
        mouseUpX = mouseevent.getX();
        mouseIn = false;
        if(mouseUpX > prevX)
            xInc = 1;
        else
            xInc = -1;
    }
}

And here is the code for the HttpMessage.class

// FrontEnd Plus GUI for JAD
// DeCompiled : HttpMessage.class

import java.io.*;
import java.net.*;
import java.util.Enumeration;
import java.util.Properties;

public class HttpMessage
{

    URL servlet;
    String args;

    public HttpMessage(URL url)
    {
        servlet = null;
        args = null;
        servlet = url;
    }

    public InputStream sendGetMessage()
        throws IOException
    {
        return sendGetMessage(null);
    }

    public InputStream sendGetMessage(Properties properties)
        throws IOException
    {
        String s = "";
        if(properties != null)
            s = "?" + toEncodedString(properties);
        URL url = new URL(servlet.toExternalForm() + s);
        URLConnection urlconnection = url.openConnection();
        urlconnection.setUseCaches(false);
        return urlconnection.getInputStream();
    }

    public InputStream sendPostMessage()
        throws IOException
    {
        return sendPostMessage(null);
    }

    public InputStream sendPostMessage(Properties properties)
        throws IOException
    {
        String s = "";
        if(properties != null)
            s = toEncodedString(properties);
        URLConnection urlconnection = servlet.openConnection();
        urlconnection.setDoInput(true);
        urlconnection.setDoOutput(true);
        urlconnection.setUseCaches(false);
        urlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        DataOutputStream dataoutputstream = new DataOutputStream(urlconnection.getOutputStream());
        dataoutputstream.writeBytes(s);
        dataoutputstream.flush();
        dataoutputstream.close();
        return urlconnection.getInputStream();
    }

    private String toEncodedString(Properties properties)
    {
        StringBuffer stringbuffer = new StringBuffer();
        for(Enumeration enumeration = properties.propertyNames(); enumeration.hasMoreElements();)
        {
            String s = (String)enumeration.nextElement();
            String s1 = properties.getProperty(s);
            stringbuffer.append(URLEncoder.encode(s) + "=" + URLEncoder.encode(s1));
            if(enumeration.hasMoreElements())
                stringbuffer.append("&");
        }

        return stringbuffer.toString();
    }
}
0
 
LVL 18

Accepted Solution

by:
mgfranz earned 200 total points
Comment Utility
I believe I answered this Q...

[answered for clean-up]
0
 

Expert Comment

by:SpideyMod
Comment Utility
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now