Here are the steps im supposed to take for where im stuck at:
create a for loop that runs through your array list of values. For each iteration of the loop, you will be drawing a Rectangle to represent the current value’s bar.
In each loop, you should do the following:
1. Calculate the height of a single bar (barHeight) – Remember to use the max value you previously found.
2. Calculate the width of a single bar (barWidth) (This can be done outside the loop as well.)
3. Create a random color, and set that color – remember that a color can be created and saved into a Color variable using the Color constructor, which takes 3 int values 0-255 representing red, green, and blue.
4. Draw the Rectangle for the current bar – Start at an (x,y) of (xleft,height-barHeight), and remember to use g2.fill().
5. Calculate a new xleft for the next iteration of the loop, by adding the width of a single bar to the previous value.
Here is my code
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class BarChart
{
private int width = 0;
private int height = 0;
private ArrayList<Double> barChartValues;
private Random color;
public void BarSize(double newHeight, double newWidth)
{
newHeight = height;
newWidth = width;
ArrayList<Double> barChartValues = new ArrayList<Double>();
Random color = new Random();
}
public void add(double newValue)
{
barChartValues.add(newValue);
}
public void draw(Graphics g2)
{
double max = Collections.max(barChartValues);
int xleft = 0;
for (int i = 0; i < barChartValues.size(); i++)
{
}
}
}
This post has been edited by g00se: 17 November 2012 - 08:56 AM
Reason for edit:: Fixed code tags

New Topic/Question
Reply



MultiQuote







|