Results 1 to 5 of 5
  1. #1
    Gfunk is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default Little help with Drawing canvas needed

    Hello :)

    I am a newbie to java, and i am trying to get the user to input a value between one and 500, and have it graphed onto the drawing canvas. Im a bit stuck here and i have got the basics of it drawn onto it, but its not drawing the bars properly where i want them too. can you please have a look at my code and tell me what i am doing wrong.

    thankyou

    Java Code:
      public void plotPrices() {
        // Set up the window for drawing
        JFrame frame = new JFrame("Core: Plot of numbers");
        frame.setSize(700, 600);    // 700 pixels wide, 600 pixels high.
        DrawingCanvas canvas = new DrawingCanvas();
        frame.getContentPane().add(canvas, BorderLayout.CENTER);
        frame.setVisible(true);
        canvas.drawLine(50,500,600,500);
        canvas.drawLine(50,500,50,200);
        Scanner scan = new Scanner(System.in);
    
        System.out.println("Enter numbers between 1 & 500, end with 'close'");
        double number = 0;
        double total = 0;
        double min = Double.MAX_VALUE;
        double max = Double.MIN_VALUE;
        while(scan.hasNext()) {
        int baseX = 500;
        int baseY = 30;
        String stringValue = scan.next();
                 double nextValue = 0;
                 try {
                         nextValue = Double.parseDouble(stringValue);
                     }
                         catch(NumberFormatException nFE) {
                         if(stringValue.equals("close")) { 
                            break;
                         }
                         else {
                            System.out.println("Please enter a Number, or 'Close'"); 
                            continue;
                         }
                    }
                 
                 total = total + nextValue;
                 if(nextValue < min)
                    min = nextValue;
                 if(nextValue > max)
                    max = nextValue;
                 number++;
                 
                 
                 canvas.drawRect(nextValue, baseX, baseY, nextValue);
    
              }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Gfunk is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    What is this class "DrawingCanvas"?
    it just sets up a frame where the drawRect() goes in and so on. Where all the drawing happens. Its something our lecturer taught us

  4. #4
    Gfunk is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    no one can help? This is urgent!

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Gfunk View Post
    no one can help? This is urgent!
    Please understand that this is your urgency, not ours. You still haven't given us much to go on as we still have little clue as to what the DrawCanvas class is or does. Please read this section in the smart questions link: How To Ask Questions The Smart Way

    Best of luck.

Similar Threads

  1. Replies: 1
    Last Post: 07-16-2009, 02:15 PM
  2. Replies: 0
    Last Post: 07-05-2009, 12:31 PM
  3. Using a Canvas
    By a_klasanov in forum CLDC and MIDP
    Replies: 3
    Last Post: 12-08-2008, 10:36 AM
  4. a little help needed for card drawing
    By carlos123 in forum New To Java
    Replies: 3
    Last Post: 01-09-2008, 03:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •