DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003

    applet won't load

    DrawHouse.Java ===
    import java.applet.Applet;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.Graphics;

    public class DrawHouses extends Applet{ ArrayList houses; Point2D.Double topLeft, bottomRight; public DrawHouses(){ houses = new ArrayList(); addMouseListener(new MyMouseListener()); } private class MyMouseListener extends MouseAdapter{ public void mousePressed(MouseEvent e){ topLeft = new Point2D.Double(e.getX(),e.getY()); } public void mouseReleased (MouseEvent e){ bottomRight = new Point2D.Double(e.getX(),e.getY()); houses.add(new House(bottomRight.getX() - topLeft.getX(), bottomRight.getY() - topLeft.getY(), topLeft)); repaint(); } } public void paint(Graphics g){ for(int i = 0; i < houses.size(); i++) ((House)(houses.get(i))).draw(g); }}
    ============================= =
    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;public class House extends Applet{ public House(double x,double y) { xLeft = x; yTop = y; } public void 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); } private double xLeft; private double 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)

  2. #2
    Join Date
    Mar 2003
    Please use code tags to format your code.

    Please Edit your code so there are some carriage returns and all of the code does not appear on the same line - it's unreadable.

    "the java applet won't run... "

    Please post any error messages.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center