Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Getting a red Oval to displayed on screen

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Getting a red Oval to displayed on screen

    Hey JPF members,

    I'm a beginner in java trying to get a Red Oval to appear on screen. I'm also using a java book but im stuck with this problem. Any solution to this problem?

    As you may know I'm trying to get a red oval to appear using my guy.java source file.

    heres my code:



    public class Guy extends java.applet.Applet {

    /** initialization method that will be called after
    * applet is loaded into the browser
    */

    public void init() {
    //
    }

    public void paint(java.awt.Graphics g){
    g.drawOval(200,200,100,100);
    g.fillOval(400, 300, 75, 288);
    g.setColor(java.awt.Color.RED);
    }
    }


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Getting a red Oval to displayed on screen

    Try making a call to super(g).

    public void paint(java.awt.Graphics g){
    super(g);
    g.drawOval(200,200,100,100);
    g.fillOval(400, 300, 75, 288);
    g.setColor(java.awt.Color.RED);
    }

    Also, don't know your whole code. Try called setVisible(true) within your guy() constructor.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Getting a red Oval to displayed on screen

    Try making a call to super(g).
    No. This will not compile, I believe you mean call super.paint(g). To the original poster, is your question that the applet does not draw the circles? Are you sure? How large is your applet (if its smaller than the smallest x/y (200,200) value you will not see the graphics)

  4. The Following User Says Thank You to copeg For This Useful Post:

    javapenguin (January 13th, 2011)

  5. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting a red Oval to displayed on screen

    public class Guy extends java.applet.Applet {

    /** initialization method that will be called after
    * applet is loaded into the browser
    */

    public void init() {
    //
    }

    public void paint(java.awt.Graphics g){
    super(g);
    g.drawOval(200,200,100,100);
    g.fillOval(400, 300, 75, 288);
    g.setColor(java.awt.Color.RED);
    setVisible(true);

    So I took your advice but I get an error : Constructor call must be the first statement in a constructor. I dont understand what you mean by constructor?

  6. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Red face Re: Getting a red Oval to displayed on screen

    Yeah, that's what I meant.

    super.paint(g);

  7. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Red face Re: Getting a red Oval to displayed on screen

    Quote Originally Posted by warnexus View Post
    public class Guy extends java.applet.Applet {

    /** initialization method that will be called after
    * applet is loaded into the browser
    */

    public void init() {
    //
    }

    public void paint(java.awt.Graphics g){
    super(g);
    g.drawOval(200,200,100,100);
    g.fillOval(400, 300, 75, 288);
    g.setColor(java.awt.Color.RED);
    setVisible(true);

    So I took your advice but I get an error : Constructor call must be the first statement in a constructor. I dont understand what you mean by constructor?
    I meant super.paint(g).

    I was calling the Applet constructor with the Graphics g as a parameter.

  8. #7
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting a red Oval to displayed on screen

    All I see is a White oval and a black oval. Why is not my set color red code in effect? I want a red oval on screen

  9. #8
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Getting a red Oval to displayed on screen

    Call setColor before you draw

  10. The Following User Says Thank You to Freaky Chris For This Useful Post:

    javapenguin (January 14th, 2011)

  11. #9
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting a red Oval to displayed on screen

    Thanks Chris. Apparently the book did not even told me about this. Make perfect sense nevertheless set before you draw. I will remember this! Thanks a bunch Now I can move on to chapter 3

Similar Threads

  1. How to get screen size in Applet
    By anm_brr in forum Java Applets
    Replies: 2
    Last Post: August 10th, 2011, 09:21 PM
  2. Screen Resolution
    By bartonn in forum Member Introductions
    Replies: 2
    Last Post: December 16th, 2010, 06:49 AM
  3. JTable is not fit to the screen width.
    By rajakumarjk in forum AWT / Java Swing
    Replies: 2
    Last Post: October 12th, 2010, 10:13 AM
  4. clear screen.
    By chronoz13 in forum Java Theory & Questions
    Replies: 10
    Last Post: December 5th, 2009, 07:27 AM
  5. Certain Chinese Characters not displayed properly.
    By kerwintang in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 20th, 2009, 08:23 AM