Results 1 to 20 of 20
- 01-31-2009, 03:59 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 9
- Rep Power
- 0
-
Please give more details on just what you've done and what your stuck on. The more info you can give, the better folks can help you.
Best of luck
- 01-31-2009, 04:19 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 9
- Rep Power
- 0
nothing here anymore to see
Last edited by kiduut; 01-31-2009 at 07:32 AM.
-
So what I mean is what have you done/tried so far to make your plot?
Last edited by Fubarable; 01-31-2009 at 04:30 AM.
- 01-31-2009, 04:34 AM #5
Member
- Join Date
- Dec 2008
- Posts
- 9
- Rep Power
- 0
nothing here anymore to see
Last edited by kiduut; 01-31-2009 at 07:32 AM.
-
So if I were you I'd do the following:
1) Change the above code so that it is no longer static but a true OOPs class that can generate data points for another class when necessary
2) Step away from the computer, get a few sheets of paper and a pencil and start brain-storming what classes will be necessary for my graphics program and start thinking about what states (fields) these classes will have and what behaviors (methods) they will have.
3) If I didn't know graphics and Swing, I'd start going through the appropriate Sun tutorials, and then
4) Use this outline and knowledge to create a plotting program.
I think that the planning portion is the best part here as it's where your creative juices really come into full force. So why not have at it, and then come on back if you get stuck at a specific step.
Best of luck.
- 01-31-2009, 05:27 AM #7
Member
- Join Date
- Dec 2008
- Posts
- 9
- Rep Power
- 0
hmm. where is point 0 and 0 on java plot?
-
It's wherever you decide to place it (me, I'd place it in the middle of a JPanel), but I think that you may be getting ahead of yourself with that question. You need to plan the general behaviors of the classes before you start worrying about specifics.
- 01-31-2009, 06:24 AM #9
Member
- Join Date
- Dec 2008
- Posts
- 9
- Rep Power
- 0
nothing here anymore to see
Last edited by kiduut; 01-31-2009 at 07:31 AM.
-
As suggested above, please first read the sun graphics tutorial before attempting any graphics coding. Your code shows that you haven't read the tutorial yet, and so you don't have the knowledge framework for us to even begin trying to help you. This tutorial will give you the basics you'll need to be able to get started.
Also, do your code in Swing not AWT to take full advantage of the latest enhancements of Java GUI.
Also, do your code in a JPanel. Then when it works right, you can put into a JApplet.
Again, best of luck.
edit: I've looked at your code and it's time for you to fess up: you found that code online and posted it without understanding it, didn't you? I mean using RenderingHints before you know to override a paint (or for Swing paintComponent) method? Come on now, don't hurt yourself like this -- read the tutorials and learn to understand it. You'll thank me for this recommendation, trust me.Last edited by Fubarable; 01-31-2009 at 06:41 AM.
- 01-31-2009, 06:40 AM #11
Member
- Join Date
- Dec 2008
- Posts
- 9
- Rep Power
- 0
Please, just little help. i dont have time for manuals atm:(
-
Here's a link to the tutorial: Trail: 2D Graphics (The Java™ Tutorials)
Not a good thing to say around here as:Please, just little help. i dont have time for manuals
a) Your time management issues are just that, your issues not ours, and
b) We like to help people learn, not cheat.
Again, best of luck.
-
Other suggestions:
1) try to do most of your calculations outside of the paint or paintComponent method, especially the time-intensive Math-trigonometry methods. The painting methods needs to be short and fast, and so the calculations could be done in some initialization method. Obviously any calculations needed for the rendering of the graphics itself need to be in the painting methods.
2) try not to put everything in one method. Otherwise you'll have a "God" method that tries to do too much and becomes impossible to debug or extend. Divide and conquer is the key.Last edited by Fubarable; 01-31-2009 at 07:10 AM.
-
Another suggestion: again, do your plotting in a JPanel in one class, the calculating in another class, and the applet in a third class. Your plotting jpanel class could have this outline:
and the applet could look something like this:Java Code:import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JPanel; public class DrawPanel extends JPanel { private int[] xArray; private int[] yArray; private int maxX, minX, maxY, minY; // domain and range of our data points // the trig calculations could be done in another class and then // the final resulting arrays passed to the DrawPanel when ready public DrawPanel(int[] xArray, int[] yArray) { this.xArray = xArray; this.yArray = yArray; // iterate through the points to get the max X and Y and mins. } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // use these guys and the max and min X and Ys to figure out // how to translate the data points so that they are well // positioned in the panel int width = getWidth(); int height = getHeight(); // draw your x axis and y axis here // use a for loop to draw your x and y points. // You may wish to use small circles to give them some size } }
Java Code:import javax.swing.JApplet; public class PlotApplet extends JApplet { public void init() { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGUI(); } }); } catch (Exception e) { System.err.println("createGUI didn't successfully complete"); } } private void createGUI() { // you'll need to create a class to calculate your points PlotCalculatePoints calcPoints = new PlotCalculatePoints(); int[] xArray = calcPoints.getXArray(); // extract data arrays from class int[] yArray = calcPoints.getYArray(); // create JPanel and add data points DrawPanel drawPanel = new DrawPanel(xArray, yArray); // add to applet's contentPane getContentPane().add(drawPanel); } }Java Code:class PlotCalculatePoints { public int[] getXArray() { // TODO do calculations } public int[] getYArray() { // TODO do calculations } }
- 01-31-2009, 07:48 AM #15
i hate it when they do that. they think they can just rip off the ans and erase their tracks. Just wait till i find the cache data.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
-
that ungrateful sun of a witch. someone to add to the never-to-help list.
- 01-31-2009, 07:57 AM #17
google didn't cache the page!! ran away codes...
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
-
how do you find the cache data?
edit: never mind
again, I will do all in my power to see that he receives no more help here again.
-
Some of his code looked like so:
Java Code:public class plot extends Applet { private static final long serialVersionUID = 1L; public void joonista(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); double t, s = 0.1, m, m2, k = 0; int a = 0, u; int w = getWidth(); int h = getHeight(); g.setColor(Color.white); g.fillRect(0, 0, w, h); // Calculate array size for (t = -10; t < 10; t = t + s) { a = a + 1; } // create array according to needed size double[] xarray = new double[a], yarray = new double[a]; // calculate x and y, put them into array place a for (a = 0, t = -10; t < 10; t = t + s, a = a + 1) { xarray[a] = (10 * t) * Math.cos(t); yarray[a] = (10 * t) * Math.sin(t); } // find smallest number from x array m = xarray[0]; int index = 0; for (u = 1; u < xarray.length; u++) { if (xarray[u] < m) { m = xarray[u]; index = u; } } // find smallest number from y array m2 = yarray[0]; int index1 = 0; for (u = 1; u < yarray.length; u++) { if (yarray[u] < m2) { m2 = yarray[u]; index1 = u; } } // wich is smaller small number from y array or x array if (xarray[index] < yarray[index1]) { k = xarray[index]; } else { k = yarray[index1]; } // subtract smallest number from all numbers in arrays so we dont have any // negative numbers for (a = 0, t = -10; t < 10; t = t + s, a = a + 1) { xarray[a] = xarray[a] - k; yarray[a] = yarray[a] - k; } // draw final int PAD = 20; g.setColor(Color.green); for (a = xarray.length - 2; a > 0; a = a - 1) { double x1 = PAD + a * xarray[a]; double y1 = h - PAD - yarray[a]; double x2 = PAD + (a + 1) * xarray[a]; double y2 = h - PAD - yarray[a + 1]; g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } } }
- 03-02-2009, 03:42 PM #20
Brave New World
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Similar Threads
-
How to plot a dot graph
By Manfizy in forum Java 2DReplies: 3Last Post: 01-28-2009, 02:57 PM -
graph + combo box
By abelah in forum New To JavaReplies: 7Last Post: 10-13-2008, 05:36 PM -
Bar Graph
By Zosden in forum Advanced JavaReplies: 2Last Post: 04-28-2008, 06:52 AM -
Need Help for Dot Plot Graph
By BHCluster in forum Java 2DReplies: 5Last Post: 04-15-2008, 02:54 PM -
Graph DPS and BFS implementation
By hey in forum New To JavaReplies: 1Last Post: 01-09-2008, 09:19 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks