Results 1 to 2 of 2
  1. #1
    ntagrafix's Avatar
    ntagrafix is offline Member
    Join Date
    Nov 2009
    Location
    Denmark
    Posts
    29
    Rep Power
    0

    Question How to duplicat drawOval horizontally?

    Hi guyz,

    I have a paint method that draws a circle with crossed-diagonal lines as follows

    Java Code:
    public void paint(Graphics Grafix){
    Grafix.drawLine(10, 20, 50, 70);
    Grafix.drawLine(50, 20, 10, 70);
    Grafix.drawOval(5, 20, 50, 50);
    }
    Now I need to duplicate the circle with cross 6 time horizontally, how can i do that and place it into a Jpanel. below is my what i've.

    Java Code:
            panel_1 = new JPanel();
            panel_1.setBackground(Color.green);
            add(panel_1);
    Thanks a lot:)
    Life is not perfect, but the way you live it can make it perfectly wongerful :cool:

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    1) Learn standard Java naming conventions. Every book, tutorial, or example I've seen posted in the forums follow these basic standards. Don't make up your own. Variable name should NOT start with an upper cased character.

    2) Custom painting on a component is done by overriding the paintComponent() method NOT the paint() method. However, I am going to suggest a different approach.

    Create a custom Icon. In this case the custom painting is done in the paintIcon(...) method.

    Now you can add the icon to multiple JLabels and add your labels to your panel.

    If you need more help post your SSCCE showing the problem.

Posting Permissions

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