Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!

Tim Collins

Greenhorn
+ Follow
since May 31, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tim Collins

thanks, that worked. I just initialized a JLabel with an imageicon and it worked like a charm....
18 years ago
I am trying to insert an image into a very basic swing application. I did some research and attempted to create an ImageIcon object, using the constructor that implements a filename, then tried to add it to a JPanel. The ImageIcon is created without issue, but when I try to add it to the JPanel, I get an "unresolved symbol" error. My theory is that ImageIcon is not the right object to try to insert into the panel. Any ideas?
Thanks
Tim
18 years ago
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());
}
}
}
19 years ago
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
19 years ago
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
19 years ago
Tom,
I know this doesn't help you at all, but the whole purpose of this site is to share information, right? ;-)
How do you export graphics object (like in a paint method) to a jpg file? I have been looking for a few days now trying to figure out just that thing...
Let me Know
Tim
19 years ago
Hi all,
I am writing a java applet that displays a line graph, and I am wondering if it is possible to draw vertical strings in the applet. the drawString method only allows you to give it a startX and a startY, which means that the only way to draw that string is horizontal.
If you know how to do this, I would appreciate any information you could provide.
Thanks.
19 years ago
Hopefully someone still looks here I see the last entry was the 16th. I need help creating a graph with a Java program/applet. Right now, I am looking at the need for a dynamic line graph, based on data that is acquired from a file. Examples would be fantastic, but a resource where I could possibly find this info would also be helpful. (ASAP)
Thanks
Tim Collins
19 years ago