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?
/*
* 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?