[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

02/21/2001 at 07:42AM PST, ID: 20081402
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Graphing Applet (Strip)

Asked by jcardenas in Java Programming Language, New to Java Programming

Tags: 0xffcc33, color, stripchart

Dear friend i have the following applet code, i need your support to reviews this code because with my symantec visual cafe show severals errors on the compilation time.

Thanks by cheking my code.

thanks,

Jairo

**************Applet begin here*********************

import java.applet.Applet;
import java.net.*;
import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
import java.util.Enumeration;

public class StripChart extends Applet implements Runnable
{
 static int chartWidth = 300;
 static int chartHeight = 120;

 static Color chartFG = new Color(0x336699);
 static Color chartBG = new Color(0xFFCC33);

    private Image graph;
    private Graphics graphGraphics;
    private Graphics screenGraphics;

    private Thread runner;

    long currentTick = -1;

    public StripChart() {
        setBackground(chartBG);
        setForeground(chartFG);
    }

    public void addNotify() {
        super.addNotify();
        try {
            screenGraphics = getGraphics();
            graph = createImage(chartWidth, chartHeight);
            graphGraphics = graph.getGraphics();
            graphGraphics.setColor(chartBG);
            graphGraphics.fillRect(0,0,chartWidth,chartHeight);
        } catch (Exception e) { throw new Error("Hosed!"); }
    }
    public Dimension getPreferredSize() { return new Dimension(chartWidth, chartHeight); }

    public void setBackground(Color bg) { chartBG = bg; }
    public void setForeground(Color fg) { chartFG = fg; }
    public Color getBackground() { return chartBG; }
    public Color getForeground() { return chartFG; }


    private int value;  // only here to implement a fake data feed

    /** this should ask the 'world' for the next point to be charted */
    protected int getNextChartValue()
    {
        int K = 8; // max +/- change per tick
        int delta = ((int)( Math.random()*(2*K+1))) - K;
        value -= delta;
        if (value<0) value = 0;
        if (value>=chartHeight) value = chartHeight-1;
        return value;
    }

    private int getImageOffset() {
        if (currentTick<chartWidth) return 0;
        return (int) ((currentTick+1) % chartWidth);
    }

    private void setNextPoint(int val) {
        if (val<0) val=0;
        if (val>=chartHeight) val=chartHeight-1;
        int x = (int) (++currentTick % chartWidth);
        graphGraphics.setColor(chartBG);
        graphGraphics.drawLine(x,0, x,chartHeight-val);
        graphGraphics.setColor(chartFG);
        graphGraphics.drawLine(x,chartHeight-val, x,chartHeight);
        paint(screenGraphics);
    }

    public void run() {
        long mark = System.currentTimeMillis();

        while (runner!=null) {

            setNextPoint(getNextChartValue());

            // just some timing stuff
            if (currentTick % chartWidth == chartWidth - 1) {
                long now = System.currentTimeMillis();
                double elapsed = (now - mark) / 1000.0;
                double frames = chartWidth;
                int fps = (int) (frames / elapsed + 0.5);
                showStatus("fps = " + fps);
                mark = now;
            }
        }
    }

    public void    init() { if (isActive()) showStatus(getAppletInfo()); }
    public void   start() { runner=new Thread(this); runner.start(); }
    public void    stop() { runner=null; }
    public void destroy() { }

    public void update(Graphics g) { paint(g); }
    public void  paint(Graphics g) {
        if (graph==null) return;
        int xoff = getImageOffset();
        g.drawImage(graph,     -xoff, 0, chartWidth, chartHeight, null);
        g.drawImage(graph, chartWidth-xoff, 0, chartWidth, chartHeight, null);
    }

    public final String getAppletInfo()
    { return "StripChart"; }

    public boolean mouseMove(Event evt, int x, int y)
    {   showStatus(getAppletInfo());
        return super.mouseMove(evt, x, y);
    }
}

class StripChartApp extends Frame implements AppletStub, AppletContext
{
 // AppletStub stuff
 public boolean isActive() { return false; }
 public URL getDocumentBase() { return null; }
 public URL getCodeBase() { return null; }
 public String getParameter(String name) { return null; }
 public AppletContext getAppletContext() { return this; }
 public void appletResize(int width, int height) {}

 // AppletContext stuff
 public Applet getApplet(String name) { return null; }
 public Enumeration getApplets() { return null; }
 public AudioClip getAudioClip(URL url) { return null; }
 public Image getImage(URL url) { return null; }
 public void showDocument(URL url) {}
 public void showDocument(URL url, String target) {}
 public void showStatus(String txt)
    {if (status!=null) status.setText(txt); }

    static private Applet applet = null;
    static private Label  status = null;

    StripChartApp(String title) {
        super(title);
        setLayout(new BorderLayout());
        add("Center", applet=new StripChart());
        add("South",  status=new Label());
        applet.setStub(this);
    }
    public static void main(String args[]) {
        Frame frame = new StripChartApp("StripChart");
        frame.pack();
        frame.show();
        applet.init();
        applet.start();
        frame.addWindowListener(new WindowAdapter()
            { public void windowClosing(WindowEvent e) { System.exit(0); } });
    }
}

*******applet end here******************
[+][-]02/21/01 07:49 AM, ID: 5864069

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, New to Java Programming
Tags: 0xffcc33, color, stripchart
Sign Up Now!
Solution Provided By: rkenworthy
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02/21/01 08:57 AM, ID: 5864437

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/21/01 10:44 AM, ID: 5864947

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74