2 Replies - 417 Views - Last Post: 18 March 2009 - 07:55 PM Rate Topic: -----

#1 dsptl  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 20
  • Joined: 09-February 09

StockChart - Bar graph (Please Help)

Posted 18 March 2009 - 06:22 PM

Problem Number 8:

Posted Image
Posted Image

My work so far:


import jpb.*;
import java.awt.*;
import java.util.*;
public class StockChart
{
  public static void main(String[] args)
	{
	  int width = 0;
	  int height = 0;
	  String StockName;
	  String m, t, w, r, f, w1, h;
	  double mon, tues, wed, thur, fri;
	  
	  SimpleIO.prompt("Enter the name of the stock:");
	  StockName = SimpleIO.readLine();
	  SimpleIO.prompt("Enter stock price on Monday:");
	  m = SimpleIO.readLine();
	  SimpleIO.prompt("Enter stock price on Tuesday:");
	  t = SimpleIO.readLine();
	  SimpleIO.prompt("Enter stock price on Wednesday:");
	  w = SimpleIO.readLine();
	  SimpleIO.prompt("Enter stock price on Thursday:");
	  r = SimpleIO.readLine();
	  SimpleIO.prompt("Enter stock price on Friday:");
	  f = SimpleIO.readLine();
	  SimpleIO.prompt("Enter width of chart:");
	  w1 = SimpleIO.readLine();
	  width = Integer.parseInt(w1);
	  SimpleIO.prompt("Enter height of chart:");
	  h = SimpleIO.readLine();
	  height = Integer.parseInt(h);
	  

	  DrawableFrame df = new DrawableFrame("Chart for " + StockName);
	  df.show();
	  df.setSize(width, height);
	  Graphics g = df.getGraphicsContext();

	  {
	  g.setColor(Color.red);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  g.setColor(Color.blue);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  g.setColor(Color.green);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  g.setColor(Color.magenta);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  g.setColor(Color.cyan);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  }

	}
}





Please Help.....From this point we don't know what to do and he never went over this :confused: :( :confused:

Is This A Good Question/Topic? 0
  • +

Replies To: StockChart - Bar graph (Please Help)

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: StockChart - Bar graph (Please Help)

Posted 18 March 2009 - 07:28 PM

You should never do that:
Graphics g = df.getGraphicsContext();



the way to do that is to call the repaint() method

That will call your paint() method that might look like this

public void paint(Graphics g)
	  {
	  g.setColor(Color.red);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  g.setColor(Color.blue);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  g.setColor(Color.green);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  g.setColor(Color.magenta);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  g.setColor(Color.cyan);
	  g.fillRect(0, (height/2), (width/5), (height/2));
	  }


Was This Post Helpful? 1
  • +
  • -

#3 dsptl  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 20
  • Joined: 09-February 09

Re: StockChart - Bar graph (Please Help)

Posted 18 March 2009 - 07:55 PM

thx,but I still don't know how to do last four points (black squares)


PLEASE HELP

This post has been edited by dsptl: 18 March 2009 - 07:55 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1