The classes AppletStub and AppletContext also needs to be imported.
either have it as,
import java.applet.AppletStub;
import java.applet.AppletContext;
import java.applet.Applet;
or
import java.applet.*;
-sgoms
Main Topics
Browse All TopicsDear 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(cha
graphGraphics.fillRect(0,0
} 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(cha
graphGraphics.drawLine(x,0
graphGraphics.setColor(cha
graphGraphics.drawLine(x,c
paint(screenGraphics);
}
public void run() {
long mark = System.currentTimeMillis()
while (runner!=null) {
setNextPoint(getNextChartV
// 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(ne
{ public void windowClosing(WindowEvent e) { System.exit(0); } });
}
}
*******applet end here******************
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: rkenworthyPosted on 2001-02-21 at 07:49:12ID: 5864069
I didnt even look at what the code does or run it, but its not compiling because you are only importing the Applet class, not the others.
ie
import java.applet.Applet;
To fix the problem, change the above line to:
import java.applet.*;
Cheers,
Rob