Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding a graph to your application

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i have a java application and want to graph the ordered pairs.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFreeChart
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it working I needed to put set and get statements and call the arrays from there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic