import java.applet.Applet;
import java.awt.Graphics;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Point2D;
import java.awt.Graphics2D;
publicclass House extends Applet
{
public House(double x,double y)
{
xLeft = x;
yTop = y;
}
publicvoid draw(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
resize(210,210);
Point2D.Double k1 = new Point2D.Double(100,100);
Point2D.Double k2 = new Point2D.Double(50,150);
Point2D.Double k3 = new Point2D.Double(150,150);
Line2D.Double sideOne = new Line2D.Double(k1,k2);
Line2D.Double sideTwo = new Line2D.Double(k1,k3);
Line2D.Double sideThree = new Line2D.Double(k2,k3);
Rectangle2D.Double leftRectangle = new Rectangle2D.Double(100,150,30,60);
Rectangle2D.Double rightRectangle = new Rectangle2D.Double(160,150,30,60);
Rectangle2D.Double windowRectangle = new Rectangle2D.Double(40,50,20,40);
Rectangle2D.Double panesRectangle = new Rectangle2D.Double(20,25,10,20);
Rectangle2D.Double doorrectangle = new Rectangle2D.Double(85,100,20,40);
Line2D.Double leftLine = new Line2D.Double(100,150,30,60);
Line2D.Double rightLine = new Line2D.Double(160,150,30,60);
Line2D.Double window = new Line2D.Double(40,50,20,40);
Line2D.Double panes = new Line2D.Double(20,25,10,20);
Line2D.Double door = new Line2D.Double(85,100,20,40);
g2.translate(210,210);
g2.draw(sideOne);
g2.draw(sideTwo);
g2.draw(sideThree);
g2.draw(leftLine);
g2.draw(rightLine);
g2.draw(window);
g2.draw(panes);
g2.draw(door);
}
privatedouble xLeft;
privatedouble yTop;
}
======================================= the House compile but then the java applet won't run... what did I do wrong? Can some1 fix it and comment where I did wrong? Much Appreciated. Thanks. (I'm new to this forum)
In an applet, the JVM looks for the init method first. For it to be recognized, its signature must be:
public void init()
Next the start with the following signature executes:
public void start()
The paint method is next, with the signature:
public void paint(Graphics g)
The paint method is actually executed whenever it is necessary for the JVM to render the applet on the screen, so it may run many times duirng the execution of the applet.
Other methods may also run in response to events, such as the clicking of a mouse, but this depends on whether the code for the applet invokes methods in response to events.
If the browser leaves the page on which the applet is located, the stop method is called:
public void stop()
If the browser returns to the applet's page, start runs again, theh paint and any other methods invoked by events that may occur.
At some time the applet terminates, either because the browser is closed or leaves the applet's page for a sufficient amount of time, or because the code explicitly terminates it. When this happens, the destroy method is called, which as the signature:
public void destroy()
All the methods described above for applets are inherited from JApplet. Therefore, they exist already, even if you do not write them for your applet. In fact, you can create an applet without writing any methods at all, but you will find it rather dull to execute, since it will not do anything. If you are skeptical, try running this!