Results 1 to 5 of 5
  1. #1
    usha is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default how to draw oval using Graphics object

    Hi,


    I have one requirement.I have drawn one oval on panel using Graphics2D object.
    But i want to display the oval on panel immediately after executing the class with out performing any action(mouse click event). I had written the code in constructor.Its not displaying. This one working perfectly when i place the code on any event of the panel. please help me.

    Thanks in advance,
    Usha.

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

    Default

    Perhaps you will want to reveal to us the libraries that you're using (Swing vs AWT), and to show us the code you've used so far, especially the one that's not working?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

  4. #4
    usha is offline Member
    Join Date
    Oct 2010
    Posts
    11
    Rep Power
    0

    Default how to draw oval using Graphics object

    I used the following code. When i call this function from constructor its not working. Its working when i call this drawing function from mouse event of jPanel.



    public class Example extends JFrame{
    public Example(){
    JPanel panel=new JPanel();
    .....................................
    ..........................................
    drawing();
    }}




    public void drawing(){
    rd=(java.awt.Graphics2D)Panel.getGraphics();
    RenderingHints rh = new RenderingHints(
    RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    rd.setRenderingHints(rh);
    rd.drawOval(4,3,30,30);
    rd.setColor(new java.awt.Color(83,125,249));
    rd.fillOval(5,4,29,29);
    rd.setColor(java.awt.Color.black);
    rd.drawOval(p,q,7,7);
    }

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

Similar Threads

  1. Object Draw canvas Text
    By kyle.g in forum New To Java
    Replies: 0
    Last Post: 07-27-2010, 10:54 PM
  2. do I need to dispose of my Graphics object?
    By gib65 in forum AWT / Swing
    Replies: 3
    Last Post: 07-06-2010, 06:04 AM
  3. Draw Graphics on top of another
    By child in forum AWT / Swing
    Replies: 9
    Last Post: 01-17-2010, 05:14 PM
  4. How to set line width in Graphics object?
    By inc_123 in forum New To Java
    Replies: 8
    Last Post: 08-15-2009, 11:34 PM
  5. Trying to use Graphics draw methods
    By Lang in forum SWT / JFace
    Replies: 5
    Last Post: 03-26-2008, 06:49 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
  •