Am I missing something?

Discussion in 'Java' started by primeattheark via JavaKB.com, Feb 27, 2006.

  1. I typed this in from an old "teach yourself java 1.2 in 24 hours"

    /*
    * JavaMan.java
    */
    import java.awt.*;
    import javax.swing.*;
    import java.awt.geom.*;
    /**
    *
    *
    */
    public class JavaMan extends javax.swing.JApplet {

    float height;
    float width;

    /** Creates a new instance of JavaMan */
    public JavaMan() {
    }

    public void init(){
    setBackground(Color.yellow);

    }

    public void paint(Graphics2D screen){
    Graphics2D screen2D = (Graphics2D) screen;
    height = (float) getSize().height;
    width = (float) getSize().width;
    screen2D.setColor(Color.black);
    RoundRectangle2D.Float border = new RoundRectangle2D.Float(10F, 10F,
    width-20, height-20, 15F, 15F);
    screen2D.draw(border);

    screen2D.setColor(Color.gray);
    Rectangle2D.Float box = new Rectangle2D.Float(200F, 90F, 100F, 100F);
    screen2D.fill(box);

    screen2D.setColor(Color.blue);
    for (int x = 200; x < 300; x += 5)
    for(int y = 90; y < 190; y += 5){
    Rectangle2D.Float r = new Rectangle2D.Float(x, y, 5, 5);
    screen2D.draw(r);
    }

    screen2D.setColor(Color.black);
    Line2D.Float ln1 = new Line2D.Float(200F, 110F, 170F, 115F);
    Line2D.Float ln2 = new Line2D.Float(170F, 115F, 160F, 90F);
    Line2D.Float ln3 = new Line2D.Float(160F, 90F, 150F, 94F);
    Line2D.Float ln4 = new Line2D.Float(160F, 90F, 153F, 85F);
    Line2D.Float ln5 = new Line2D.Float(160F, 90F, 158F, 83F);
    Line2D.Float ln6 = new Line2D.Float(160F, 90F, 163F, 84F);
    screen2D.draw(ln1);
    screen2D.draw(ln2);
    screen2D.draw(ln3);
    screen2D.draw(ln4);
    screen2D.draw(ln5);
    screen2D.draw(ln6);

    screen2D.setColor(Color.white);
    Ellipse2D.Float head = new Ellipse2D.Float(220F, 30F, 60F, 60F);
    screen2D.fill(head);

    screen2D.setColor(Color.green);
    Ellipse2D.Float leftEye = new Ellipse2D.Float(245F, 45F, 5F, 5F);
    Ellipse2D.Float rightEye = new Ellipse2D.Float(255F, 45F, 5F, 5F);
    screen2D.fill(leftEye);
    screen2D.fill(rightEye);

    screen2D.setColor(Color.black);
    Rectangle2D.Float mouth = new Rectangle2D.Float(245F, 65F, 15F, 15F);
    screen2D.fill(mouth);

    screen2D.setColor(Color.magenta);
    GeneralPath chapeau = new GeneralPath();
    chapeau.moveTo(205f, 43F);
    chapeau.lineTo(305F, 40F);
    chapeau.lineTo(240F, 15F);
    chapeau.lineTo(205F, 43F);
    chapeau.closePath();
    screen2D.fill(chapeau);

    }
    }

    It is meant to draw a 2D man. However what happens is, the window flickers
    yellow for a second and it just goes white. I have checked for typo errors
    but no avail.

    What am I missing?

    --
    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200602/1
     
    primeattheark via JavaKB.com, Feb 27, 2006
    #1
    1. Advertising

  2. primeattheark via JavaKB.com

    Oliver Wong Guest

    "primeattheark via JavaKB.com" <u10528@uwe> wrote in message
    news:5c847c5a659c0@uwe...
    >I typed this in from an old "teach yourself java 1.2 in 24 hours"
    >

    [snipped]
    > public class JavaMan extends javax.swing.JApplet {

    [snipped]
    >
    > public void paint(Graphics2D screen){


    Replace the above line with:

    public void paint(Graphics screen){

    [snipped]
    >
    > }
    > }
    >
    > It is meant to draw a 2D man. However what happens is, the window flickers
    > yellow for a second and it just goes white. I have checked for typo errors
    > but no avail.
    >
    > What am I missing?


    The JApplet class has a paint(Graphics) method. The intention is for you
    to override that method; however, what the code you've written does is
    created a completely different method instead, instead of overriding the
    different one, due to the differents in the types of the argument.

    - Oliver
     
    Oliver Wong, Feb 27, 2006
    #2
    1. Advertising

  3. Thanks Oliver.

    I suppose I could not see the wood for the trees with this one.

    thanks again.

    Rob.

    Oliver Wong wrote:
    >>I typed this in from an old "teach yourself java 1.2 in 24 hours"

    >
    >[snipped]
    >> public class JavaMan extends javax.swing.JApplet {

    >[snipped]
    >
    >> public void paint(Graphics2D screen){

    >
    >Replace the above line with:
    >
    >public void paint(Graphics screen){
    >
    >[snipped]
    >
    >> }
    >> }

    >[quoted text clipped - 4 lines]
    >>
    >> What am I missing?

    >
    > The JApplet class has a paint(Graphics) method. The intention is for you
    >to override that method; however, what the code you've written does is
    >created a completely different method instead, instead of overriding the
    >different one, due to the differents in the types of the argument.
    >
    > - Oliver


    --
    Message posted via http://www.javakb.com
     
    primeattheark via JavaKB.com, Feb 28, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kathy Burke
    Replies:
    1
    Views:
    289
    David Wier
    Nov 25, 2003
  2. Guest
    Replies:
    4
    Views:
    502
    Guest
    Oct 13, 2004
  3. Pekka Järvinen
    Replies:
    2
    Views:
    692
    Richard Tobin
    Apr 29, 2008
  4. Replies:
    4
    Views:
    236
    Tad McClellan
    Jun 1, 2007
  5. Replies:
    9
    Views:
    176
Loading...

Share This Page