Am I missing something?

  • Thread starter primeattheark via JavaKB.com
  • Start date
P

primeattheark via JavaKB.com

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?
 
O

Oliver Wong

primeattheark via JavaKB.com said:
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
 
P

primeattheark via JavaKB.com

Thanks Oliver.

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

thanks again.

Rob.

Oliver said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top