Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Am I missing something?

Thread view: 
primeattheark - 27 Feb 2006 18:42 GMT
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?
Oliver Wong - 27 Feb 2006 18:59 GMT
>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
primeattheark - 28 Feb 2006 00:34 GMT
Thanks Oliver.

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

thanks again.

Rob.

>>I typed this in from an old "teach yourself java 1.2 in 24 hours"
>
[quoted text clipped - 22 lines]
>
>    - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.