Results 1 to 14 of 14

Thread: Need help

  1. #1
    fluffy is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default Need help

    I am new to Java...I am trying to draw several images in one drawing panel, but i can,t able to do..here are the details
    The overall drawing panel is size 500 x 350. Its background color
    is cyan. The rectangular area behind each grid of circles is green, and the background of the circles is yellow.
    The rectangles and circles are outlined in black. Each grid also has a pair of lines drawn across it in an "X"
    pattern. The six figures on your drawing panel should have the following properties.
    Description (x, y) position size of subfigure circles per subfigure rows/cols
    top-left (0, 0) 100 x 100 10 N / A
    top-middle (160, 0) 60 x 60 6 N / A
    top-right (250, 30) 100 x 100 5 N / A
    bottom-left (10, 170) 48 x 48 4 3 x 3
    bottom-middle (180, 190) 24 x 24 3 5 x 5
    bottom-right (340, 170) 72 x 72 9 2 x 2

    The 100x100 subfigure has 10 circles, and each circle has a gap of 5 pixels from any others (a total of 20 gaps for both directions...the thing is I have to use only parameters and for loops..could any one help me for this .

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    And what is your question?

    What have you done so far?

    regards,
    sukatoa

  3. #3
    fluffy is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default need help

    import java.awt.*;

    public class Circles {
    public static void main(String[] args) {
    DrawingPanel panel = new DrawingPanel(500, 350);
    panel.setBackground(Color.CYAN);
    Graphics g = panel.getGraphics();

    g.setColor(Color.YELLOW);
    for(int i=0; i<10; i++) {
    g.fillCircle(i*5, i*5, 100-i*5, 100-i*5);

    g.setColor(Color.BLACK);

    g.drawOval(0, 0, 100-i*5, 100-i*5);
    }
    }
    }
    i just tried to draw the first fig but not able to.....

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Hi fluffy,

    First of all, welcome to the Java Forums.

    I have one question to ask from you. Are use any Java IDE for your coding? Or just work on a text editor like Notepad?

  5. #5
    fluffy is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default

    i have written the code on jGrasp

  6. #6
    fluffy is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default

    Hey
    could any one can help me to solve this problem....please

  7. #7
    fireball2008 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by sukatoa View Post
    And what is your question?

    What have you done so far?

    regards,
    sukatoa
    ask those question too many times, without answer the question the askers ask.

  8. #8
    fireball2008 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by fluffy View Post
    import java.awt.*;

    public class Circles {
    public static void main(String[] args) {
    DrawingPanel panel = new DrawingPanel(500, 350);
    panel.setBackground(Color.CYAN);
    Graphics g = panel.getGraphics();

    g.setColor(Color.YELLOW);
    for(int i=0; i<10; i++) {
    g.fillCircle(i*5, i*5, 100-i*5, 100-i*5);

    g.setColor(Color.BLACK);

    g.drawOval(0, 0, 100-i*5, 100-i*5);
    }
    }
    }
    i just tried to draw the first fig but not able to.....

    I think the class have to extends JFrame and setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

    and then add(panel);

    let me know if I answer your questions.

  9. #9
    fireball2008 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    Here is one of the example I done:
    import javax.swing.JFrame;
    import java.awt.*;

    public class BallApp extends JFrame {
    private BallPanel _ballP, _ball2;
    public BallApp(String title)
    {super(title);
    setSize(510,510);
    setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    _ballP = new BallPanel();
    add(_ballP);

    setVisible(true);}
    public static void main(String[] args){
    BallApp app = new BallApp("Color Chaning Ball");
    }
    }


    note that ballPanel is a panel class you have to add panel in to the Frame

  10. #10
    fluffy is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default

    i need to write the code in import java.awt.*
    by using for loops and parameters...
    i don't understand this import javax.swing.JFrame;

  11. #11
    fireball2008 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by fluffy View Post
    i need to write the code in import java.awt.*
    by using for loops and parameters...
    i don't understand this import javax.swing.JFrame;
    I know you have to write in awt, but in order to display it you have to display it in JFrame , JFrame is like a board that you can put the panel on. import is just importing the classes in java. for example import java.awt.* is like import the class in awt that you will use like the panels and many other. so import javax.swing.JFrame is like importing the JFrame class so you can use it.

  12. #12
    fireball2008 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    Here is modifield version check if works:
    import java.awt.*;
    import javax.swing.JFrame;


    public class Circles extends JFrame{
    public static void main(String[] args) {
    DrawingPanel panel = new DrawingPanel(500, 350);
    add(panel);
    setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    panel.setBackground(Color.CYAN);
    Graphics g = panel.getGraphics();

    g.setColor(Color.YELLOW);
    for(int i=0; i<10; i++) {
    g.fillCircle(i*5, i*5, 100-i*5, 100-i*5);

    g.setColor(Color.BLACK);

    g.drawOval(0, 0, 100-i*5, 100-i*5);
    }
    }
    }

  13. #13
    fluffy is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default

    Thanks fireball2008 for the response....
    i tried to compile that code but it is showing the errors
    Circles.java:11: cannot find symbol
    symbol : method fillCircle(int,int,int,int)
    location: class java.awt.Graphics
    g.fillCircle(i*5, i*5, 100-i*5, 100-i*5);
    ^
    1 error

    i wrote fillOval instead of circle then it compiled but the thing is the output was not the same i am trying to get....i need to fill the circles with yellow color and the outline of the circle should be black..but the thing is here i am getting the circles filled with both yellow and black..i need only outline of the circle should be black

  14. #14
    fireball2008 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    well, I didn't know about drawing the outline black, but I am confused with
    "the circles filled with both yellow and black" what do u mean by that, it should only fill with one color, try delete the line
    "g.setColor(Color.BLACK);" and see what happens.

Posting Permissions

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