We help IT Professionals succeed at work.

WRITING APPLET

MMEREKI
MMEREKI asked
on
Could you please help me with writing the applet program which can draw a roundavel(house)with two front windows(square) and a door between them.



Comment
Watch Question

What about:

package aa;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class MyApplet extends Applet {

    /**Construct the applet*/
    public MyApplet() {
    }
    public void paint(Graphics g) {
        // roof
     Polygon roof = new Polygon(new int[] {0, 140, 70}, new int[] {50, 50, 5}, 3);
        g.setColor(Color.red);
        g.fillPolygon(roof);

        // house
        g.setColor(Color.yellow);
        g.fillRect(15, 50, 110, 100);

        // windows
        g.setColor(Color.cyan);
        g.fillRect(30, 70, 20, 20);
        g.fillRect(90, 70, 20, 20);

        // door
        g.setColor(Color.darkGray);
        g.fillRect(60, 95, 20, 55);
    }

    /**Get Applet information*/
    public String getAppletInfo() {
        return "Applet Information";
    }
    /**Get parameter info*/
    public String[][] getParameterInfo() {
        return null;
    }
}

This is just a very simple demo. You could change coordinates, colors, etc.
Tell me if you need a more complex example or additional help...

Author

Commented:
Dear ia ia ia 1

I have the program but it doesn't give an output.I m using visual j++.I have tried to edit it but it still gives the same answer. Dont put color  I will put color when I call the class using HTML.Dont give complex examples please because I'm Still learnig this language.
How are you starting the applet?
1. Compile the class I've sent you.
2. Place in your classes directory html file with the following content:
<html>
<head>
<title>
HTML Test Page
</title>
</head>
<body>
aa.MyApplet will appear below in a Java enabled browser.<br>
<applet
  codebase = "."
  code     = "aa.MyApplet.class"
  name     = "TestApplet"
  width    = "400"
  height   = "300"
  hspace   = "0"
  vspace   = "0"
  align    = "top"
>
</applet>
</body>
</html>
3. Open this html file with a java enabled browser.
Do you receive any errors? Do you see the house?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Homework?
Hey, MMEREKI, what's up?
Did you manage to run the applet?

Author

Commented:
Thanks ia ia ia 1 I managed to run the alpplet by changing some other things.
Ok, what about the points, then? :))

Author

Commented:
ok i will give you 150 points then. thanks
Well? :)
Well? :)
This question is LOCKED with a Proposed Answer.  If it helps you, great, accept it and grade it to close.  If not, reject it and comment as to why or what else is needed.

Few additional experts will join this collaboration effort, once a question has been locked.  Just want to confirm this to you.  If more than one expert helps you, you can always split points or award additional help in a new question, within the same topic area.  If you need help from us, post a zero point question here, and include the link:

EXPERT INPUT ON OUTCOME ALWAYS WELCOME.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Moondancer
Community Support Moderator @ Experts Exchange
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange

Explore More ContentExplore courses, solutions, and other research materials related to this topic.