This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes adding a graph to your application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "adding a graph to your application" Watch "adding a graph to your application" New topic
Author

adding a graph to your application

Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Hi I have an application that produces ordered pairs which I need to graph. How do I connect the two. I thought of an applet but do not know how to send the ordered pairs to the applet.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Is the question how to graphically display a graph of ordered pairs generated in a Java application or are you asking how to get the ordered pairs from a non-Java application?
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Yes i have a java application and want to graph the ordered pairs.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Presuming you're doing this as a desktop client you would use Swing. There's a tutorial here. A short synopsis of what you'd need to do:

1. Write a custom JComponent that overrides paintComponent() to draw a point for each ordered pair and then draw a line between each point.
2. Create a JFrame.
3. Add that custom JComponent to that JFrame.
4. Size and position it if necessary, then make it visible.

There's a Swing forum here (where this may end up) and you can ask questions if you have issues anywhere along the way. Note that if my presumption about how you want to display this is inaccurate then all of this advice is worthless.
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
thanks I knew to us swing I just didn't know how to use it in an application. I'll let you know if I get it to work
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
JFreeChart


There is no emoticon for what I am feeling!
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
I just want to make sure I got this right. I have a class with the swing in it then call the class from my original application, right? Now I think it makes sense.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Donna Bachner:
I just want to make sure I got this right. I have a class with the swing in it then call the class from my original application, right? Now I think it makes sense.


What kind of application is your original application? What sort of UI does it sport? Have you written Swing GUIs before? Have you studied the Swing Tutorial?
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
The application is a Java file, and I have done swing but not on an application. The swing tutorial was a good refresher. I have not programed in Java for about a year and half. I have been using C++ but perfer Java.
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Now I have two stupid questions. I figured out the swing, but when I go to include it on my program it gives me an error. Here is the code:
import java.lang.*;
#include Graph.java;
Question 2 is when I want to call something from my application to the swing class what is the syntax.
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
oops, I just figured out part of the problem is I confused C++ and Java. I still don't know hoe to call my graphing funtion from my application. I think i'm almost done with this program. A few more line.
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Another question. This code should graph the points from my application. How do I call it in my application and am I missing anything in "Graph"?I have the imports I just didn't copy them. The name of the applicqation is VIBE.


public class Graph extends JFrame
{
public Graph()
{
super("plots points");
setSize(500, 500);
setVisible(true);
}
public void paint(Graphics g)
{
super.paint(g);
for(int i = 0; i< VIBE.xCoord.length; i++)
{
g.setColor(Color.RED);
g.drawOval((int)VIBE.xCoord[i], (int)VIBE.yCoord[i], 10,10);
g.fillOval((int)VIBE.xCoord[i], (int)VIBE.yCoord[i], 10,10);
}
for(int j = 0; j < VIBE.POIxCoord.length; j++)
{
g.setColor(Color.BLUE);
g.drawOval((int)VIBE.POIxCoord[j], (int)VIBE.POIyCoord[j], 10,10);
g.fillOval((int)VIBE.POIxCoord[j], (int)VIBE.POIyCoord[j], 10,10);
}
}
}
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
I got it working I needed to put set and get statements and call the arrays from there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding a graph to your application
 
Similar Threads
java 2d
passing parameters to applet dynamically
Graphs in swing
Urgent
save applet as image