public void layoutContainer(Container target) {
    //      System.out.println("Laying out container " + target);
    super.layoutContainer(target);
    if (free != null) { // what is free??
      Point loc = free.getLocation();
      Dimension sz = free.getSize();

      // System.out.println("Laying out free component " + free);
      free.setBounds(loc.x, loc.y, sz.width, sz.height);
    }
  }
Beispiel #2
0
  /* Constructor */
  public MovingObject(
      int radius,
      int x,
      int y,
      double vx,
      double vy,
      double mass,
      double k,
      Planet planet,
      Color color,
      AudioClip collision,
      Component parent,
      int panelHeight) {
    this.radius = radius;
    pos_x = x;
    pos_y = y;
    x_speed = vx;
    y_speed = vy;
    ballMass = mass;

    this.k = k; // arbitrary constant used for gravity

    this.planet = planet;

    this.parent = parent;

    this.panelHeight = panelHeight;

    x_leftout = radius;
    x_rightout = parent.getSize().width - radius;
    y_upout = radius + panelHeight;
    y_downout = parent.getSize().height - radius;

    this.color = color;

    img = ((Applet) parent).getImage(((Applet) parent).getCodeBase(), "earth.gif");

    this.collision = collision;
  }
 /** This method is required to implement the Printable interface */
 public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
   if (pageIndex >= 1) {
     return NO_SUCH_PAGE;
   }
   Graphics2D g2 = (Graphics2D) g;
   Dimension cs = printTarget.getSize();
   g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
   double imageableWidth = pageFormat.getImageableWidth();
   double imageableHeight = pageFormat.getImageableHeight();
   double scale = 1;
   if (cs.width >= imageableWidth) {
     scale = imageableWidth / cs.width;
   }
   g2.scale(scale, scale);
   // g2.translate((imageableWidth - cs.width)*scale/2,
   //             (imageableHeight - cs.height)*scale/2);
   printTarget.paintAll(g2);
   return Printable.PAGE_EXISTS;
 }
  public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
    // Component printMe = getPrintComponent();

    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.black); // set default foreground color to black

    // for faster printing, turn off double buffering
    // RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);

    Dimension d = printComponent.getSize(); // get size of document
    double panelWidth = d.width; // width in pixels
    double panelHeight = d.height; // height in pixels
    double pageHeight = pf.getImageableHeight(); // height of printer page
    double pageWidth = pf.getImageableWidth(); // width of printer page
    double scale = pageWidth / panelWidth;
    int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);

    // make sure we don't print empty pages
    if (pageIndex >= totalNumPages) {
      return Printable.NO_SUCH_PAGE;
    }

    // shift Graphic to line up with beginning of print-imageable region
    g2.translate(pf.getImageableX(), pf.getImageableY());

    // shift Graphic to line up with beginning of next page to print
    g2.translate(0f, -pageIndex * pageHeight);

    // scale the page so the width fits...
    g2.scale(scale, scale);

    // PRINT IT!
    printComponent.paint(g2);

    return Printable.PAGE_EXISTS;
  }
 public Sprite(Component component, Image image, Point position, Point motionVector) {
   // Seed a random number generator
   // for this sprite with the sprite
   // position.
   rand = new Random(position.x);
   this.component = component;
   this.image = image;
   setSpaceOccupied(
       new Rectangle(
           position.x, position.y, image.getWidth(component), image.getHeight(component)));
   this.motionVector = motionVector;
   // Compute edges of usable graphics
   // area in the Frame.
   int topBanner = ((Container) component).getInsets().top;
   int bottomBorder = ((Container) component).getInsets().bottom;
   int leftBorder = ((Container) component).getInsets().left;
   int rightBorder = ((Container) component).getInsets().right;
   bounds =
       new Rectangle(
           0 + leftBorder,
           0 + topBanner,
           component.getSize().width - (leftBorder + rightBorder),
           component.getSize().height - (topBanner + bottomBorder));
 } // end constructor
 /**
  * A very nice trick is to center windows on screen, this method helps you to to that.
  *
  * @param compo The <code>Component</code> to center
  */
 public static void centerComponent(Component compo) {
   compo.setLocation(
       new Point(
           (getScreenDimension().width - compo.getSize().width) / 2,
           (getScreenDimension().height - compo.getSize().height) / 2));
 }
 public BackgroundImage(Component component, Image image) {
   this.component = component;
   size = component.getSize();
   this.image = image;
 } // end construtor