aspose file tools*
The moose likes Applets and the fly likes Applet not running Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet not running" Watch "Applet not running" New topic
Author

Applet not running

Tim Collins
Greenhorn

Joined: May 31, 2001
Posts: 9
Hello,
I am a beginner Java user, and I am writing a Java Applet that reads out of a file and presents data in a line graph. That works very well, and I have it looking just the way I want it when I run it in Java's Appletviewer. My problem is that when I try to look at the web page in a browser, the applet doesn't show up at all. I have tried in Internet Explorer and in Netscape, (both recent versions), and I get the same thing. nothing! ;-(
Any hints as to why this doesn't work, and what I can do to make it work, would be greatly appreciated!
Thanks
Tim
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Tim,
Check out this article for some enlightenment!
http://developer.java.sun.com/developer/technicalArticles/Security/Signed/
Enjoy,
Manfred
Tim Collins
Greenhorn

Joined: May 31, 2001
Posts: 9
Thanks guys,
I figured out that my problem was that I was using File I/O, which turned out to be more trouble than it was worth. So I am going to use CGI to send the data.
I do have another problem in that my applet runs fine in IE, but not in Netscape. I know Java is enabled (because I checked) and I have gone to Sun's website and viewed applets on their site with Netscape.
I personally don't like Netscape, but apparently most of the people that would use my program do, so I need to figure it out.
Any info you could provide that would help, would be great.
Thanks again,
Tim
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Could you post what exception is being thrown? Look in the Java Console.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Tim Collins
Greenhorn

Joined: May 31, 2001
Posts: 9
Null Pointer Exception.
For the purpose of allowing you to help, below is my code. http://midnight.vtc.vsc.edu/~tcollins/stats/test2.html is the HTML document.
Thanks
Tim
/*****************************************************************************
* Programmer : Tim Collins
* Date Created : June 5, 2001
* Date Last Updated : June 7, 2001
* Filename : LineGraph.java
* Description : The LineGraph Java Applet is used to create line a line
* : graph out of data that is sent to it using the Java
* : applet tag in the HTML document. See chart.cgi for
* : how the data is organized before being sent.
******************************************************************************
* NOTE : File I/O would have been the best way to do this, but File I/O in a
* : Java applet is more trouble than it is worth. The CGI script that
* : feeds the data to the applet is much more affective, and efficient.
*******************************************************************************/
import java.applet.*;
import java.awt.*;
public class LineGraph extends Applet
{
public void paint(Graphics g)
{
try
{
/*********************************************************************
* Then Declare all of my default values.
*********************************************************************/
int heightofGraph = 200, startX = 90, startY = 50;
int DistanceBetween = 20, count=0,index = 0, numberOfDataPoints = 12;
int numberOfYLines = heightofGraph / DistanceBetween;
int location = 0, lastLocation = 0, maxScale = 100;
int divFactor = heightofGraph / maxScale;
int numberOfInts =3;// The fourth int will be captured after the loop.
String[] lines = new String[numberOfDataPoints];
String[][] techInfo=new String[numberOfDataPoints][numberOfDataPoints];
int [][] techData = new int[numberOfDataPoints][numberOfInts+2];
String [] month = new String[numberOfDataPoints];
/**********************************************************************
* USAGE: lines[count].indexOf(string searchString, int beginIndex);
* Returns the index(int) of the specified string.
* ex.
* String str = "Collins, Tim";
* int location = str.indexOf(',', 0);
* location would equal 7.
* USAGE: lines[count].substring(int beginIndex,int endIndex);
* Returns the string in between beginIndex and endIndex.
* ex.
* String newString = str.substring(0,5);
* newString would equal "Colli";
*********************************************************************/
String techName=getParameter("techName");
String legendString = getParameter("legend");
String[] legendInfo = new String[numberOfDataPoints+1];
for(count=0;count<numberOfDataPoints;count++)
lines[count] = getParameter("" + count);
location = legendString.indexOf(',', 0);
/*********************************************************************
* File IO in a Java Applet is a difficult task to pull off. It is not
* impossible, but this is much better. These values are taken from the
* HTML page when the applet is called. The CGI script will read
* through the file and send the values.
**********************************************************************/
for(count = 0;count<numberOfDataPoints;count++)
{
location = legendString.indexOf(',',lastLocation+1);
if(location < 0 | | lastLocation > legendString.length())
break;
legendInfo[count] = legendString.substring(lastLocation,location);
lastLocation = location;
if(count > 0)
legendInfo[count] = legendInfo[count].substring(1);
}
legendInfo[count] = legendString.substring(lastLocation+1,legendString.
length());
for(count=0;count<numberOfDataPoints;count++)
{
/********************************************************************
* Reset the location variables for each line, and set the first
* locaton to the index of the first comma.
*******************************************************************/
location = 0; lastLocation = 0;
location = lines[count].indexOf(',', 0);
/********************************************************************
* For each string, set first location to the next comma. Then store
* the string in between the commas into the String array.
*******************************************************************/
location = lines[count].indexOf(',',lastLocation+1);
month[count] = lines[count].substring(lastLocation,location);
lastLocation = location;
for(index = 0; index < numberOfInts; index++) // Get Integers.
{
location = lines[count].indexOf(',',lastLocation+1);
techData[count][index] = Integer.parseInt(lines[count].
substring(lastLocation+1,location));
lastLocation = location;
}
techData[count][index] = Integer.parseInt(lines[count].
substring(lastLocation+1,lines[count].
length()));
}
/***********************************************************************
* Declare a new array called formattedData. This is where the data
* will be stored once it is formatted correctly for drawPolyLine.
**********************************************************************/
int [][] formattedData = new int[4][12];
/***********************************************************************
* Read through the original array techData. techData has the data in
* organized by the month (the way it comes in the file). Each line in
* formattedData is one of the 4 categories.
**********************************************************************/
for(count=0;count<4;count++)
{
for(index=0;index<12;index++)
formattedData[count][index] = techData[index][count];
}
/**********************************************************************
* Declare a new array called convertedData. This is where the data
* will be stored once it is converted so it draws correctly in the
* Java Applet window.
*********************************************************************/
int [][] convertedData = new int[4][12];
/***********************************************************************
* Convert the data values so they will draw correctly. Subtract the
* data multiplied by the divFactor, and subtracted from the bottom
* point in the graph.
**********************************************************************/
for(count=0;count<4;count++)
{
for(index=0;index<12;index++)
{
convertedData[count][index] = (heightofGraph+startY) -
(formattedData[count][index]
*divFactor);
}
}
/***********************************************************************
* usage: g.drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
**********************************************************************/
g.drawString("BTV In-Line Process Capability - " + techName, startX, 15);
/***********************************************************************
* Declare the color array used to fill in the graph and the legend.
* NOTE: There are more colors available than just these 4.
**********************************************************************/
Color [] lineColors = {Color.blue, Color.cyan, Color.green,
Color.magenta};
int GridNum = heightofGraph / divFactor;
int subFactor = GridNum / 5;
DistanceBetween = 40;
int widthofGraph = DistanceBetween*numberOfDataPoints;
g.drawString("Legend",startX+widthofGraph + (startX/2),startY+(startY/2));
/*********************************************************************
* This for loop is responsible for drawing the horizontal lines on
* graph.
********************************************************************/
for(count = 0; count < (numberOfYLines/divFactor); count++)
{
g.drawString(" " + GridNum, startX-35,
(startY+(count*DistanceBetween))+4);
g.drawLine((startX - 10), startY+(count*DistanceBetween),
widthofGraph+startX, startY+(count*DistanceBetween));
GridNum -= subFactor;
}
int [] xPoints = new int[numberOfDataPoints];
int XPosition = startX;
/*********************************************************************
* Fill the xPoints array which will be used in conjunction with the
* convertedData array to create the Polyline. This for loop is also
* responsible for drawing the tick marks at the bottom of the line
* graph (and the months that correspond to the tick marks), and the
* plotted points (fillOval) on the graph.
********************************************************************/
for(count = 0; count < numberOfDataPoints;count++)
{
xPoints[count] = XPosition;
g.drawLine(XPosition,startY+heightofGraph-5,XPosition,
startY+heightofGraph+10);
XPosition += DistanceBetween;
g.setColor(Color.black);
g.drawString(month[count], startX-10+(40*count),startY+heightofGraph+30);
for(index=0;index<4;index++)
{
// Set the color for each set of points
g.setColor(lineColors[index]);
g.fillOval(xPoints[count]-2,convertedData[index][count]-2,5,5);
}
}
/*********************************************************************
* This for loop draws the lines on the graph. It sets the color each
* time through the loop, draws the line, and also adds to the legend
* the information tha the line represents.
********************************************************************/
for(count=0;count<4;count++)
{
g.setColor(lineColors[count]);
g.drawPolyline(xPoints,convertedData[count],12);
g.drawString(legendInfo[count+1], startX+widthofGraph+(startX/2),startY+startY+(20*count));
}
/**********************************************************************
* Draw the outside of the Graph. Set the color to black.
**********************************************************************/
g.setColor(Color.black);
g.drawRect(startX, startY, widthofGraph, heightofGraph);
}
catch(Exception e)
{
System.out.println("Error: " + e.toString());
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet not running
 
Similar Threads
Applet Notified.Please help.
Keyboard shortcuts for 'Menu bars in an Applet' not working!!
Need Help for RMI
Calling an applet method from JavaScript
What is "java.lang.ClassFormatError: bad magic number"?