Esempio n. 1
0
  public void init() {
    try {
      this.imLogo = this.getImage("icon.png");
      tracker.addImage(this.imLogo, 0);
      tracker.waitForID(0);
    } catch (InterruptedException inex) {

    }
    try {
      this.imHelp = this.getImage("helpphoto.png");
      tracker.addImage(this.imHelp, 1);
      tracker.waitForID(1);
    } catch (InterruptedException ie) {
    }
    this.fontTitle = new Font("GB2312", Font.BOLD, 25);
    this.fontText = new Font("GB2312", Font.PLAIN, 18);
    this.setBackground(Color.BLACK);
    this.setForeground(Color.WHITE);
    this.timer =
        new Timer(
            500,
            new ActionListener() {
              public void actionPerformed(ActionEvent ev) {
                world = new OSCWorld();
                world.onEnter();
                repaint();
                timer.stop();
              }
            });
    this.timer.start();
  }
Esempio n. 2
0
 /**
  * Load images (used for preloading images).
  *
  * @param images Array of <code>Image</code> instances to preload.
  * @param comp Component that will observe the loading state of the images.
  */
 public static void loadImages(Image[] images, Component comp) {
   MediaTracker tracker = new MediaTracker(comp);
   for (int i = 0; i < images.length; i++) tracker.addImage(images[i], 0);
   try {
     tracker.waitForID(0);
   } catch (InterruptedException ignore) {
   }
 }
Esempio n. 3
0
 /**
  * Loads all images to be used by the GUI, and waits for them to be fully loaded before returning.
  */
 private void loadImages() {
   MediaTracker tracker = new MediaTracker(this);
   Toolkit tk = Toolkit.getDefaultToolkit();
   background = loadImage(tk, "images/background.gif", tracker);
   try {
     tracker.waitForID(0);
   } catch (InterruptedException ie) {
   }
 }
Esempio n. 4
0
 public RotatePanel(Image image) {
   this.image = image;
   MediaTracker mt = new MediaTracker(this);
   mt.addImage(image, 0);
   try {
     mt.waitForID(0);
   }
   catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 5
0
  public getPicInfo(Frame father) {
    try {
      FileDialog diag = new FileDialog(father);
      diag.setVisible(true);
      m_Img =
          getToolkit()
              .getImage(diag.getDirectory() + diag.getFile())
              .getScaledInstance(W, H, Image.SCALE_SMOOTH);
      MediaTracker mt = new MediaTracker(this);
      mt.addImage(m_Img, 0);
      mt.waitForAll();
      PixelGrabber grab = new PixelGrabber(m_Img, 0, 0, W, H, m_Pix, 0, W);
      grab.grabPixels();
      m_ImgSrc = new MemoryImageSource(W, H, m_Pix, 0, W);
      m_Img = createImage(m_ImgSrc);
      System.out.println("Wait HERE !");
    } catch (InterruptedException e) {

    }
  }
Esempio n. 6
0
  public void init() {
    MediaTracker mt = new MediaTracker(this);

    URL url = getClass().getResource("tiger.gif");

    try {
      image = createImage((ImageProducer) url.getContent());
      mt.addImage(image, 0);
      mt.waitForID(0);
    } catch (Exception e) {
      e.printStackTrace();
    }
    imw = image.getWidth(this);
    imh = image.getWidth(this);
    pixels = new int[imw * imh];

    try {
      PixelGrabber pg = new PixelGrabber(image, 0, 0, imw, imh, pixels, 0, imw);
      pg.grabPixels();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseMoved(MouseEvent e) {
            int mx = e.getX(), my = e.getY();

            if (mx > 0 && mx < imw && my > 0 && my < imh) {
              int pixel = ((int[]) pixels)[my * imw + mx];

              int red = defaultRGB.getRed(pixel),
                  green = defaultRGB.getGreen(pixel),
                  blue = defaultRGB.getBlue(pixel),
                  alpha = defaultRGB.getAlpha(pixel);

              showStatus("red=" + red + " green=" + green + " blue=" + blue + " alpha=" + alpha);
            }
          }
        });
  }
Esempio n. 7
0
  /** ****************** Open & Read an Image ********************** */
  void OpenImage2() {
    int returnVal = jfc.showOpenDialog(IPToolKit.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      file1 = jfc.getSelectedFile();
      String path = file.getAbsolutePath();
      //	image = Toolkit.getDefaultToolkit().getImage(path);

      try {
        try {
          inImage1 = new FileImageInputStream(file1);
          len1 = (int) inImage1.length();
          byteArray1 = new byte[len1];
          // System.out.println(len);
          inImage1.read(byteArray1, 0, len1);
          image1 = Toolkit.getDefaultToolkit().createImage(byteArray1);
          MediaTracker t = new MediaTracker(this);
          t.addImage(image1, 0);

          try {
            t.waitForID(1);
          } catch (Exception eeee) {
            System.out.println(eeee);
          }

          w1 = image1.getWidth(null);
          h1 = image1.getHeight(null);

          // System.out.println(w+"\t"+h);

        } catch (Exception fnfe) {
          JOptionPane.showMessageDialog(this, "File: Not Found");
        }
      } catch (Exception ice) {

        JOptionPane.showMessageDialog(this, "File I/O Error");
      }
    }
  }
Esempio n. 8
0
 /*
 	This could live in the desktop script.
 	However we'd like to get it on the screen as quickly as possible.
 */
 public static void startSplashScreen() {
   int width = 275, height = 148;
   Window win = new Window(new Frame());
   win.pack();
   BshCanvas can = new BshCanvas();
   can.setSize(width, height); // why is this necessary?
   Toolkit tk = Toolkit.getDefaultToolkit();
   Dimension dim = tk.getScreenSize();
   win.setBounds(dim.width / 2 - width / 2, dim.height / 2 - height / 2, width, height);
   win.add("Center", can);
   Image img = tk.getImage(Interpreter.class.getResource("/bsh/util/lib/splash.gif"));
   MediaTracker mt = new MediaTracker(can);
   mt.addImage(img, 0);
   try {
     mt.waitForAll();
   } catch (Exception e) {
   }
   Graphics gr = can.getBufferedGraphics();
   gr.drawImage(img, 0, 0, can);
   win.setVisible(true);
   win.toFront();
   splashScreen = win;
 }
Esempio n. 9
0
 /**
  * Loads an image from a file.
  *
  * @param tk The toolkit to be used to load the image.
  * @param file The name of the file containing the image.
  * @param tracker The media tracker tracking the progress of the load.
  * @return The image that was loaded, as an Image object.
  */
 private Image loadImage(Toolkit tk, String file, MediaTracker tracker) {
   Image result = tk.createImage(file);
   tracker.addImage(result, 0);
   return result;
 }
Esempio n. 10
0
  /** Création de l'intérieur de la fenêtre */
  private void initConteneur() {
    // le fond
    fond = getToolkit().getImage("./images/preference/bomber_fond.gif");
    tracker = new MediaTracker(this);
    tracker.addImage(fond, 0);
    try {
      tracker.waitForID(0);
    } catch (Exception a) {
      System.out.println("Erreur lors chargement de l'image: initConteneur() Preference");
      a.printStackTrace();
    }

    // le layout manager
    GridBagLayout layout = new GridBagLayout();
    setLayout(layout);
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 10;
    c.weighty = 10;
    c.ipadx = 10;
    c.ipady = 10;
    c.fill = GridBagConstraints.BOTH;

    // label "Joueurs:"
    Label lbl_joueurs = new Label("Joueurs:");
    lbl_joueurs.setAlignment(Label.CENTER);
    lbl_joueurs.setFont(new Font("SansSerif", Font.BOLD, 16));
    lbl_joueurs.setBackground(Color.black);
    lbl_joueurs.setForeground(Color.red);
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 6;
    c.gridheight = 1;
    c.insets = new Insets(20, 10, 10, 10);
    c.anchor = GridBagConstraints.SOUTH;
    layout.setConstraints(lbl_joueurs, c);
    add(lbl_joueurs);

    // choix de couleur du joueur ayant l'identifiant 0
    choix_couleur0 = new Choice();
    choix_couleur0.addItem("rouge");
    choix_couleur0.addItem("bleu");
    choix_couleur0.addItemListener(this);
    choix_couleur0.setBackground(Color.red);
    choix_couleur0.setForeground(Color.black);
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 2;
    c.gridheight = 1;
    c.insets = new Insets(10, 10, 5, 20);
    c.anchor = GridBagConstraints.EAST;
    layout.setConstraints(choix_couleur0, c);
    add(choix_couleur0);

    // nom du joueur ayant l'identifiant 0
    txt_joueur0 = new TextField(noms[0]);
    c.gridx = 2;
    c.gridy = 1;
    c.gridwidth = 4;
    c.gridheight = 1;
    c.insets = new Insets(10, 10, 5, 20);
    c.anchor = GridBagConstraints.WEST;
    layout.setConstraints(txt_joueur0, c);
    add(txt_joueur0);

    // choix de couleur du joueur ayant l'identifiant 1
    choix_couleur1 = new Choice();
    choix_couleur1.addItem("bleu");
    choix_couleur1.addItem("rouge");
    choix_couleur1.addItemListener(this);
    choix_couleur1.setBackground(Color.blue);
    choix_couleur1.setForeground(Color.black);
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 2;
    c.gridheight = 1;
    c.insets = new Insets(10, 10, 20, 20);
    c.anchor = GridBagConstraints.EAST;
    layout.setConstraints(choix_couleur1, c);
    add(choix_couleur1);

    // nom du joueur ayant l'identifiant 1
    txt_joueur1 = new TextField(noms[1]);
    c.gridx = 2;
    c.gridy = 2;
    c.gridwidth = 4;
    c.gridheight = 1;
    c.insets = new Insets(10, 10, 30, 20);
    c.anchor = GridBagConstraints.WEST;
    layout.setConstraints(txt_joueur1, c);
    add(txt_joueur1);

    // label "Nombre De Vies:"
    Label lbl_nbvies = new Label("Nombre De Vies:");
    lbl_nbvies.setAlignment(Label.CENTER);
    lbl_nbvies.setFont(new Font("SansSerif", Font.BOLD, 14));
    lbl_nbvies.setBackground(Color.black);
    lbl_nbvies.setForeground(Color.yellow);
    c.gridx = 0;
    c.gridy = 4;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.insets = new Insets(20, 10, 5, 10);
    c.anchor = GridBagConstraints.CENTER;
    layout.setConstraints(lbl_nbvies, c);
    add(lbl_nbvies);
    // un choix possible
    cbg_vies = new CheckboxGroup();
    Checkbox cb;
    for (int i = 1; i <= 5; i++) {
      if (i == nb_vies) cb = new Checkbox("" + i, cbg_vies, true);
      else cb = new Checkbox("" + i, cbg_vies, false);
      c.gridx = i;
      c.gridy = 4;
      c.gridwidth = 1;
      c.gridheight = 1;
      c.insets = new Insets(20, 10, 5, 10);
      c.anchor = GridBagConstraints.CENTER;
      layout.setConstraints(cb, c);
      add(cb);
    } // for

    // label "Nombre	De Victoires:"
    lbl_victoires = new Label();
    lbl_victoires.setAlignment(Label.CENTER);
    lbl_victoires.setFont(new Font("SansSerif", Font.BOLD, 14));
    lbl_victoires.setText("Nombre De Victoires: " + nb_victoires);
    lbl_victoires.setBackground(Color.black);
    lbl_victoires.setForeground(Color.green);
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.insets = new Insets(20, 10, 5, 10);
    c.anchor = GridBagConstraints.CENTER;
    layout.setConstraints(lbl_victoires, c);
    add(lbl_victoires);

    // choix du nombre de victoires entre un 1 et 9
    sb_victoires = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 1, 10);
    sb_victoires.setUnitIncrement(1);
    sb_victoires.setBlockIncrement(2);
    sb_victoires.addAdjustmentListener(this);
    sb_victoires.setValue(nb_victoires);
    c.gridx = 1;
    c.gridy = 6;
    c.gridwidth = 5;
    c.gridheight = 1;
    c.insets = new Insets(20, 10, 5, 10);
    c.anchor = GridBagConstraints.CENTER;
    layout.setConstraints(sb_victoires, c);
    add(sb_victoires);

    // tirage aléatoire des niveaux
    cb_aleatoire = new Checkbox("Niveaux Aléatoires", aleatoire);
    cb_aleatoire.setFont(new Font("SansSerif", Font.BOLD, 14));
    cb_aleatoire.setBackground(Color.black);
    cb_aleatoire.setForeground(Color.magenta);
    c.gridx = 0;
    c.gridy = 8;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.insets = new Insets(20, 12, 5, 10);
    c.anchor = GridBagConstraints.EAST;
    layout.setConstraints(cb_aleatoire, c);
    add(cb_aleatoire);

    // label "FPS:" nombre de frames par seconde
    lbl_fps = new Label();
    lbl_fps.setAlignment(Label.CENTER);
    lbl_fps.setFont(new Font("SansSerif", Font.BOLD, 14));
    lbl_fps.setText("FPS: " + fps);
    lbl_fps.setBackground(Color.black);
    lbl_fps.setForeground(Color.orange);
    c.gridx = 0;
    c.gridy = 10;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.insets = new Insets(20, 10, 5, 10);
    c.anchor = GridBagConstraints.CENTER;
    layout.setConstraints(lbl_fps, c);
    add(lbl_fps);

    // choix du nombre de frames par seconde
    sb_fps = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 1, 51);
    sb_fps.setUnitIncrement(1);
    sb_fps.setBlockIncrement(10);
    sb_fps.addAdjustmentListener(this);
    sb_fps.setValue(fps);
    c.gridx = 1;
    c.gridy = 10;
    c.gridwidth = 5;
    c.gridheight = 1;
    c.insets = new Insets(20, 10, 5, 10);
    c.anchor = GridBagConstraints.CENTER;
    layout.setConstraints(sb_fps, c);
    add(sb_fps);

    // bouton de confirmation
    button_ok = new Button("Ok");
    c.gridx = 0;
    c.gridy = 12;
    c.gridwidth = 6;
    c.gridheight = 1;
    c.insets = new Insets(20, 5, 20, 5);
    c.anchor = GridBagConstraints.CENTER;
    layout.setConstraints(button_ok, c);
    add(button_ok);
    button_ok.addActionListener(this);
  } // initConteneur()
Esempio n. 11
0
  public void actionPerformed(ActionEvent e) {
    String arg = (String) e.getActionCommand();

    /** ******************** Open an Image **************** */
    if (e.getSource() == m_Open) {
      int returnVal = jfc.showOpenDialog(IPToolKit.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = jfc.getSelectedFile();
        String path = file.getAbsolutePath();
        //	image = Toolkit.getDefaultToolkit().getImage(path);

        try {
          try {
            inImage = new FileImageInputStream(file);
            len = (int) inImage.length();
            byteArray = new byte[len];
            // System.out.println(len);
            inImage.read(byteArray, 0, len);
            image = Toolkit.getDefaultToolkit().createImage(byteArray);
            MediaTracker t = new MediaTracker(this);
            t.addImage(image, 0);

            try {
              t.waitForID(0);
            } catch (Exception eeee) {
              System.out.println(eeee);
            }

            w = image.getWidth(null);
            h = image.getHeight(null);

            // System.out.println(w+"\t"+h);

          } catch (Exception fnfe) {
            JOptionPane.showMessageDialog(this, "File: Not Found");
          }
        } catch (Exception ice) {

          JOptionPane.showMessageDialog(this, "File I/O Error");
        }
      }
      if (image != null) {

        pix_temp = new int[h * w];
        ImageIcon icon = new ImageIcon(image);
        lbl_img.setIcon(icon);
        setVisible(true);
      }

      pix_temp = pixel_grab(image, w, h);
      pix_temp = pix_pack(pix_temp, w, h);
      grayImageDisplay(w, h, pix_temp);
    }

    /** ****************** Add one image to another ************** */
    if (e.getSource() == mAddImg) {
      OpenImage2();
      pix_temp1 = new int[w * h];
      pix_res = new int[w * h];

      pix_temp1 = pixel_grab(image1, w1, h1);
      pix_temp1 = pix_pack(pix_temp1, w1, h1);

      for (int s = 0; s < w * h; s++) {

        pix_res[s] = pix_temp[s] + pix_temp1[s];
      }
      ;

      pix_temp1 = saturate(pix_temp1, w, h);
      imageResultDisplay(w, h, pix_res);
    }

    /**
     * *********************** Add Constant value and then use Satuartion technique ***************
     */
    if (e.getSource() == mAddSat) {
      String add_value;
      Image img_add = image;
      pixel_add = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      add_value = JOptionPane.showInputDialog("Enter Value you wish to add to the image");
      int number = Integer.parseInt(add_value);
      for (int r = 0; r < w * h; r++) {
        pixel_add[r] = number + pixel_result[r];
      }
      pixel_add = saturate(pixel_add, w, h);
      pixel_add = pix_pack(pixel_add, w, h);
      imageResultDisplay(w, h, pixel_add);
    }

    /** ************ Add constant by Wrap Around technique ********** */
    if (e.getSource() == mAddWrap) {
      String add_value;
      Image img_add = image;
      pixel_add = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      add_value = JOptionPane.showInputDialog("Enter Value you wish to add to the image");
      int number = Integer.parseInt(add_value);
      for (int r = 0; r < w * h; r++) {
        pixel_add[r] = number + pixel_result[r];
      }
      pixel_add = WrapAround(pixel_add, w, h);
      pixel_add = pix_pack(pixel_add, w, h);
      imageResultDisplay(w, h, pixel_add);
    }

    /** ****************** Subtract one image from another ************** */
    if (e.getSource() == mSubImg) {
      OpenImage2();
      pix_temp1 = new int[w * h];
      pix_res = new int[w * h];

      pix_temp1 = pixel_grab(image1, w1, h1);
      pix_temp1 = pix_pack(pix_temp1, w1, h1);

      for (int s = 0; s < w * h; s++) {
        pix_res[s] = pix_temp[s] - pix_temp1[s];
      }

      pix_temp1 = saturate(pix_temp1, w1, h1);
      imageResultDisplay(w1, h1, pix_res);
    }

    /**
     * *********************** Subtract Constant value and then use Satuartion technique
     * ***************
     */
    if (e.getSource() == mSubSat) {
      String sub_value;
      Image img_add = image;
      pixel_sub = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      sub_value = JOptionPane.showInputDialog("Enter Value you wish to subtract from the image");
      int number = Integer.parseInt(sub_value);

      for (int r = 0; r < w * h; r++) {
        pixel_sub[r] = pixel_result[r] - number;
      }

      pixel_sub = saturate(pixel_sub, w, h);
      pixel_sub = pix_pack(pixel_sub, w, h);
      imageResultDisplay(w, h, pixel_sub);
    }

    /** ************ Subtract constant by Wrap Around technique ********** */
    if (e.getSource() == mSubWrap) {
      String sub_value;
      Image img_add = image;
      pixel_sub = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      sub_value = JOptionPane.showInputDialog("Enter Value you wish to add to the image");
      int number = Integer.parseInt(sub_value);

      for (int r = 0; r < w * h; r++) {
        pixel_sub[r] = pixel_result[r] - number;
      }
      pixel_sub = WrapAround(pixel_sub, w, h);
      pixel_sub = pix_pack(pixel_sub, w, h);
      imageResultDisplay(w, h, pixel_sub);
    }

    /** ****************** Multiply one image with another ************** */
    if (e.getSource() == mMulImg) {
      OpenImage2();
      pix_temp1 = new int[w * h];
      pix_res = new int[w * h];

      pix_temp1 = pixel_grab(image1, w1, h1);
      pix_temp1 = pix_pack(pix_temp1, w1, h1);

      for (int s = 0; s < w * h; s++) {
        pix_res[s] = pix_temp[s] * pix_temp1[s];
      }

      pix_temp1 = saturate(pix_temp1, w1, h1);
      imageResultDisplay(w1, h1, pix_res);
    }

    /**
     * *********************** Multiply Constant value and then use Satuartion technique
     * ***************
     */
    if (e.getSource() == mMulSat) {
      String mul_value;
      Image img_mul = image;
      pixel_mul = new int[w * h];

      pixel_result = pixel_grab(img_mul, w, h);

      mul_value = JOptionPane.showInputDialog("Enter Value you wish to multiply to the image");
      int number = Integer.parseInt(mul_value);

      for (int r = 0; r < w * h; r++) {
        pixel_mul[r] = pixel_result[r] * number;
      }

      pixel_mul = saturate(pixel_mul, w, h);
      pixel_mul = pix_pack(pixel_mul, w, h);
      imageResultDisplay(w, h, pixel_mul);
    }

    /** ************ Multiply constant by Wrap Around technique ********** */
    if (e.getSource() == mMulWrap) {
      String mul_value;
      Image img_mul = image;
      pixel_mul = new int[w * h];

      pixel_result = pixel_grab(img_mul, w, h);

      mul_value = JOptionPane.showInputDialog("Enter Value you wish to multiply to the image");
      int number = Integer.parseInt(mul_value);
      for (int r = 0; r < w * h; r++) {
        pixel_mul[r] = pixel_result[r] * number;
      }
      pixel_mul = WrapAround(pixel_mul, w, h);
      pixel_mul = pix_pack(pixel_mul, w, h);
      imageResultDisplay(w, h, pixel_mul);
    }

    /** ****************** Divide one image by another ************** */
    if (e.getSource() == mDivImg) {

      OpenImage2();
      pix_temp1 = new int[w * h];
      pix_res = new int[w * h];

      pix_temp1 = pixel_grab(image1, w1, h1);
      pix_temp1 = pix_pack(pix_temp1, w1, h1);

      for (int s = 0; s < w * h; s++) {
        pix_res[s] = pix_temp1[s] / pix_temp[s];
      }

      // pix_temp1 = saturate(pix_temp1,w1,h1);
      pix_temp1 = WrapAround(pix_temp1, w, h);
      imageResultDisplay(w1, h1, pix_res);
    }

    /**
     * *********************** Divide by Constant value and then use Saturation technique
     * ***************
     */
    if (e.getSource() == mDivSat) {
      String div_value;
      Image img_add = image;
      pixel_div = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      div_value = JOptionPane.showInputDialog("Enter value to divide the image by");
      int number = Integer.parseInt(div_value);

      for (int r = 0; r < w * h; r++) {
        pixel_div[r] = pixel_result[r] / number;
      }

      pixel_div = saturate(pixel_div, w, h);
      pixel_div = pix_pack(pixel_div, w, h);
      imageResultDisplay(w, h, pixel_div);
    }

    /** ************ Divide constant by Wrap Around technique ********** */
    if (e.getSource() == mDivWrap) {
      String div_value;
      Image img_add = image;
      pixel_div = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      div_value = JOptionPane.showInputDialog("Enter value to divide image by");
      int number = Integer.parseInt(div_value);
      for (int r = 0; r < w * h; r++) {

        pixel_div[r] = pixel_result[r] / number;
      }
      pixel_div = WrapAround(pixel_div, w, h);
      pixel_div = pix_pack(pixel_div, w, h);
      imageResultDisplay(w, h, pixel_div);
    }

    /** ******************** Thresholding ************* */
    if (e.getSource() == mThreshold) {
      String thresh_value;
      Image img_add = image;

      pixel_result = pixel_grab(img_add, w, h);

      thresh_value = JOptionPane.showInputDialog("Enter value to threshold the image");
      int number = Integer.parseInt(thresh_value);

      for (int r = 0; r < w * h; r++) {
        if (pixel_result[r] >= number) pixel_result[r] = 255;
        else if (pixel_result[r] <= number) pixel_result[r] = 0;
      }

      pixel_result = pix_pack(pixel_result, w, h);
      imageResultDisplay(w, h, pixel_result);
    }

    if (e.getSource() == m_Save) {
      FileImageOutputStream src_img;

      int returnVal = jfc.showSaveDialog(IPToolKit.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File fileR = jfc.getSelectedFile();
        String fileToSave = file.getAbsolutePath();

        if (!fileToSave.toLowerCase().endsWith(".jpg")) {
          fileR = new File(fileToSave + ".jpg");
        }

        try {
          src_img = new FileImageOutputStream(fileR);
          buf_img = getImageFromArray(pixel_result, w, h);
          ImageIO.write(buf_img, "jpg", src_img);

        } catch (IOException ex8) {
          System.out.println(ex8);
        }
      }

      //	}

    }

    /** ***************************** Increase brightness **************** */
    if (e.getSource() == mBright) {
      String bright_value;
      Image img_add = image;

      pixel_result = pixel_grab(img_add, w, h);

      bright_value = JOptionPane.showInputDialog("Enter value to increase brightness");
      int number = Integer.parseInt(bright_value);

      for (int r = 0; r < w * h; r++) {
        pixel_result[r] = pixel_result[r] + number;
      }

      pixel_result = saturate(pixel_result, w, h);
      pixel_result = pix_pack(pixel_result, w, h);
      imageResultDisplay(w, h, pixel_result);
    }

    /** ****************** Contrast Strtching *************** */
    if (e.getSource() == mContrast) {
      String cont_value1, cont_value2;
      Image img_add = image;
      pixel_cont = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      cont_value1 = JOptionPane.showInputDialog("Enter lower limit for contrast stretch");
      int number = Integer.parseInt(cont_value1);
      cont_value2 = JOptionPane.showInputDialog("Enter higher limit for contrast stretch");
      int number1 = Integer.parseInt(cont_value2);

      for (int r = 0; r < w * h; r++) {
        if (pixel_result[r] <= number1) {

          pixel_cont[r] = pixel_result[r] - 50;
          if (pixel_cont[r] < 0) pixel_cont[r] = 0;
        } else if (pixel_result[r] >= number) {
          pixel_cont[r] = pixel_result[r] + 50;

          if (pixel_cont[r] > 255) pixel_cont[r] = 255;

        } else pixel_cont[r] = pixel_result[r];
      }

      pixel_cont = saturate(pixel_cont, w, h);
      pixel_cont = pix_pack(pixel_cont, w, h);
      imageResultDisplay(w, h, pixel_cont);
    }

    /** ******************* Low Pass Filter ****************** */
    if (e.getSource() == mlowPass) {
      int mask[][] = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}};

      pixel_result = pixel_grab(image, w, h);

      int pix_tempLow[][] = new int[h][w];

      pix_tempLow = OneD_ArrayToTwoD_Array(w, h, pixel_result);

      pix_tempLow = MaskOperation(w, h, pix_tempLow, mask);
      int pix_temp1D[] = new int[(w) * (h)];

      pix_temp1D = TwoD_ArrayToOneD_Array(w, h, pix_tempLow);

      pix_temp1D = restrict(pix_temp1D);
      pix_temp1D = pix_pack(pix_temp1D, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_temp1D);
    }

    /** ********************* High Pass Filter *************** */
    if (e.getSource() == mhighPass) {
      int mask[][] = {{-1, -1, -1}, {-1, 8, -1}, {-1, -1, -1}};

      pixel_result = pixel_grab(image, w, h);

      int pix_tempLow[][] = new int[h][w];

      pix_tempLow = OneD_ArrayToTwoD_Array(w, h, pixel_result);

      pix_tempLow = MaskOperation(w, h, pix_tempLow, mask);
      int pix_temp1D[] = new int[(w) * (h)];

      pix_temp1D = TwoD_ArrayToOneD_Array(w, h, pix_tempLow);

      pix_temp1D = saturate(pix_temp1D, w - 2, h - 2);
      pix_temp1D = restrict(pix_temp1D);
      pix_temp1D = pix_pack(pix_temp1D, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_temp1D);
    }

    /** *************************** High Boost Filter **************** */
    if (e.getSource() == mhighBoost) {
      int mask[][] = {{-1, -1, -1}, {-1, 9, -1}, {-1, -1, -1}};

      pixel_result = pixel_grab(image, w, h);

      int pix_tempLow[][] = new int[h][w];

      pix_tempLow = OneD_ArrayToTwoD_Array(w, h, pixel_result);

      pix_tempLow = MaskOperation(w, h, pix_tempLow, mask);
      int pix_temp1D[] = new int[(w) * (h)];

      pix_temp1D = TwoD_ArrayToOneD_Array(w, h, pix_tempLow);
      pix_temp1D = saturate(pix_temp1D, w - 2, h - 2);
      pix_temp1D = restrict(pix_temp1D);
      pix_temp1D = pix_pack(pix_temp1D, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_temp1D);
    }

    if (e.getSource() == m_Save) {

      for (int i = 0; i < w * h; i++) {
        System.out.println(pixel_result[i]);
      }

      FileImageOutputStream src_img;

      int returnVal = jfc.showSaveDialog(IPToolKit.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File fileR = jfc.getSelectedFile();
        String fileToSave = file.getAbsolutePath();

        if (!fileToSave.toLowerCase().endsWith(".jpg")) {
          fileR = new File(fileToSave + ".jpg");
        }

        try {
          src_img = new FileImageOutputStream(fileR);
          buf_img = getImageFromArray(pixel_result, w, h);
          ImageIO.write(buf_img, "jpg", src_img);

        } catch (IOException ex8) {
          System.out.println(ex8);
        }
      }
    }

    /** ********************* Invert and image ************ */
    if (e.getSource() == mInvert) {

      Image img_Invert = image;
      pixel_result = new int[w * h];

      pixel_result = pixel_grab(img_Invert, w, h);

      for (int r = 0; r < w * h; r++) {
        pixel_result[r] = 255 - pixel_result[r];
      }

      //	pixel_div = saturate(pixel_div,w,h);
      pixel_result = pix_pack(pixel_result, w, h);
      imageResultDisplay(w, h, pixel_result);
    }
    /** *************************** Median Filter **************** */
    if (arg.equals("Median")) {
      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = median_filter(p2d);
      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Prewits Horizontal Edge Detection ******************* */
    if (arg.equals("Prewits Horizontal")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{-1, -1, -1}, {0, 0, 0}, {1, 1, 1}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Prewits Vertical Edge Detection ******************* */
    if (arg.equals("Prewits Vertical")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Prewits Edge Detection ******************* */
    if (arg.equals("Prewits Both")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres1[] = new int[h * w];
      int pres2[] = new int[h * w];
      int pres[] = new int[h * w];
      int mask1[][] = {{-1, -1, -1}, {0, 0, 0}, {1, 1, 1}};

      pix_grabed = pixel_grab(image, w, h);

      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask1);
      pres1 = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres1 = saturate(pres1, w - 2, h - 2);
      pres1 = restrict(pres1);
      int mask2[][] = {{-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}};
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask2);
      pres2 = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres2 = saturate(pres2, w - 2, h - 2);
      pres2 = restrict(pres2);
      for (int i = 0; i < ((h - 2) * (w - 2)); i++) {
        pres[i] = pres1[i] + pres2[i];
      }

      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Sobel Horizontal Edge Detection ******************* */
    if (arg.equals("Sobel Horizontal")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);
      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Sobel Vertical Edge Detection ******************* */
    if (arg.equals("Sobel Vertical")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Sobel Edge Detection ******************* */
    if (arg.equals("Sobel Both")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres1[] = new int[h * w];
      int pres2[] = new int[h * w];
      int pres[] = new int[h * w];

      int mask1[][] = {{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}};

      pix_grabed = pixel_grab(image, w, h);

      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask1);
      pres1 = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres1 = saturate(pres1, w - 2, h - 2);
      pres1 = restrict(pres1);
      int mask2[][] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask2);
      pres2 = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres2 = saturate(pres2, w - 2, h - 2);
      pres2 = restrict(pres2);
      for (int i = 0; i < ((h - 2) * (w - 2)); i++) {
        pres[i] = pres1[i] + pres2[i];
      }

      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Roberts Edge Detection ******************* */
    if (arg.equals("Roberts")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{1, 0}, {0, -1}};
      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);

      for (int i = 1; i < h - 1; i++) {
        for (int j = 1; j < w - 1; j++) {
          pp2d[i][j] =
              ((mask[0][0] * p2d[i - 1][j - 1] + mask[1][0] * p2d[i + 1][j - 1])
                      + (mask[0][1] * p2d[i - 1][j + 1] + mask[1][1] * p2d[i + 1][j + 1]))
                  / 2;
        }
      }

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Mean Filter ******************* */
    if (arg.equals("Mean")) {
      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = mean_filt(p2d);
      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Laplacian Edge Detector ******************* */
    if (arg.equals("Laplacian")) {
      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{0, -2, 0}, {-2, 8, -2}, {0, -2, 0}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Histogram Equalization ******************* */
    if (arg.equals("Histogram Equalization")) {
      int[] pix_grabed = new int[h * w];
      int pres[] = new int[h * w];
      int cnt_pix[] = new int[256];
      int pixx[] = new int[h * w];
      int pix_pcked[] = new int[h * w];
      int pix_res[] = new int[h * w];
      int len = h * w;
      int res = 0;

      pix_grabed = pixel_grab(image, w, h);

      for (int i = 0; i < h * w; i++) {
        pixx[i] = pix_grabed[i];
      }

      for (int i = 0; i < 256; i++) {

        cnt_pix[i] = 0;
      }

      for (int i = 0; i < len; i++) {

        int ind = pixx[i];
        cnt_pix[ind]++;
      }

      for (int i = 0; i < w * h; i++) {
        float a = 0;

        for (int j = 0; j < (pixx[i] + 1); j++) {
          float b = (float) cnt_pix[j];

          float c = (float) (h * w);

          a = a + (b / c);
        }

        res = (int) (a * 255);
        if (res > 255) res = 255;

        pix_res[i] = (0xff000000 | (res << 16) | (res << 8) | res);
      }

      pix_pcked = pix_pack(pix_res, w, h);
      imageResultDisplay(w, h, pix_pcked);
    }

    if (arg.equals("Connected Component")) {
      int pix_grabed[] = new int[h * w];
      int p2d[][] = new int[h][w];
      conect_input = new int[h][w];
      conect_output = new int[h][w];

      int x1 = x_cor;
      int y1 = y_cor;

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      s = 0;
      t = 0;
      obj_size = 0;
      intensity = p2d[y1][x1];

      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          conect_input[i][j] = p2d[i][j];
          conect_output[i][j] = 0;
        }
      }

      connect(y1, x1);
      int pixx[] = new int[h * w];
      int pp[] = new int[h * w];

      pixx = TwoD_ArrayToOneD_Array(w, h, conect_output);
      pixx = saturate(pixx, w - 2, h - 2);
      pp = pix_pack(pixx, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pp);
    }

    /** ********************** Blending ******************* */
    if (arg.equals("Blending")) {

      int size;
      int hei, wid;
      if (h1 > h) hei = h1;
      else hei = h;

      if (w1 > w) wid = w1;
      else wid = w;

      size = hei * wid;
      int pix_img1[] = new int[size];
      int pix_img2[] = new int[size];
      int pix_res[] = new int[size];
      int pixx[] = new int[h1 * w1];
      double x = 0.5;
      pix_img1 = pixel_grab(image, w, h);
      OpenImage2();
      pix_img2 = pixel_grab(image1, w1, h1);

      //	 grayImageDisplay(w1,h1,pixx)

      for (int i = 0; i < size; i++) {
        pix_res[i] = (int) ((x * pix_img1[i]) + ((1 - x) * (pix_img2[i])));
      }
      int pix_pcked[] = new int[size];

      pix_pcked = pix_pack(pix_res, wid, hei);
      imageResultDisplay(wid, hei, pix_pcked);
    }

    /** ****************** Quit OR Exit **************** */
    if (arg.equals("Exit")) {
      System.exit(0);
    }
  }
Esempio n. 12
0
  //
  // Build installer window
  //
  public static void showInstallerWindow() {
    _installerFrame = new JFrame(Config.getWindowTitle());

    Container cont = _installerFrame.getContentPane();
    cont.setLayout(new BorderLayout());

    // North pane
    Box topPane = new Box(BoxLayout.X_AXIS);
    JLabel title = new JLabel(Config.getWindowHeading());
    Font titleFont = new Font("SansSerif", Font.BOLD, 22);
    title.setFont(titleFont);
    title.setForeground(Color.black);

    // Create Sun logo
    URL urlLogo = Main.class.getResource(Config.getWindowLogo());
    Image img = Toolkit.getDefaultToolkit().getImage(urlLogo);
    MediaTracker md = new MediaTracker(_installerFrame);
    md.addImage(img, 0);
    try {
      md.waitForAll();
    } catch (Exception ioe) {
      Config.trace(ioe.toString());
    }
    if (md.isErrorID(0)) Config.trace("Error loading image");
    Icon sunLogo = new ImageIcon(img);
    JLabel logoLabel = new JLabel(sunLogo);
    logoLabel.setOpaque(true);
    topPane.add(topPane.createHorizontalStrut(5));
    topPane.add(title);
    topPane.add(topPane.createHorizontalGlue());
    topPane.add(logoLabel);
    topPane.add(topPane.createHorizontalStrut(5));

    // West Pane
    Box westPane = new Box(BoxLayout.X_AXIS);
    westPane.add(westPane.createHorizontalStrut(10));

    // South Pane
    Box bottomPane = new Box(BoxLayout.X_AXIS);
    bottomPane.add(bottomPane.createHorizontalGlue());
    JButton abortButton = new JButton(Config.getWindowAbortButton());
    abortButton.setMnemonic(Config.getWindowAbortMnemonic());
    bottomPane.add(abortButton);
    bottomPane.add(bottomPane.createHorizontalGlue());
    bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));

    // Center Pane
    Box centerPane = new Box(BoxLayout.Y_AXIS);
    JLabel hidden = new JLabel(Config.getWindowHiddenLabel());
    hidden.setVisible(false);
    centerPane.add(hidden);
    _stepLabels = new JLabel[5];
    for (int i = 0; i < _stepLabels.length; i++) {
      _stepLabels[i] = new JLabel(Config.getWindowStep(i));
      _stepLabels[i].setEnabled(false);
      centerPane.add(_stepLabels[i]);

      // install label's length will expand,so set a longer size.
      if (i == STEP_INSTALL) {
        Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize();
        _stepLabels[i].setPreferredSize(dim);
      }
    }
    hidden = new JLabel(Config.getWindowHiddenLabel());
    hidden.setVisible(false);
    centerPane.add(hidden);

    // Setup box layout
    cont.add(topPane, "North");
    cont.add(westPane, "West");
    cont.add(bottomPane, "South");
    cont.add(centerPane, "Center");

    _installerFrame.pack();
    Dimension dim = _installerFrame.getSize();

    // hard code to ensure title is completely visible on Sol/lin.
    if (dim.width < 400) {
      dim.width = 400;
      _installerFrame.setSize(dim);
    }

    Rectangle size = _installerFrame.getBounds();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    size.width = Math.min(screenSize.width, size.width);
    size.height = Math.min(screenSize.height, size.height);
    // Put window at 1/4, 1/4 of screen resoluion
    _installerFrame.setBounds(
        (screenSize.width - size.width) / 4,
        (screenSize.height - size.height) / 4,
        size.width,
        size.height);

    // Setup event listners
    _installerFrame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent we) {
            installFailed("Window closed", null);
          }
        });

    abortButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            installFailed("Abort pressed", null);
          }
        });

    // Show window
    _installerFrame.show();
  }
  // ---------------------------------//
  SpriteAnimate() { // constructor
    // Load and track the images
    mediaTracker = new MediaTracker(this);
    // Get and track the background
    // image
    backGroundImage = Toolkit.getDefaultToolkit().getImage("background02.gif");
    mediaTracker.addImage(backGroundImage, 0);

    // Get and track 6 images to use
    // for sprites
    gifImages[0] = Toolkit.getDefaultToolkit().getImage("redball.gif");
    mediaTracker.addImage(gifImages[0], 0);
    gifImages[1] = Toolkit.getDefaultToolkit().getImage("greenball.gif");
    mediaTracker.addImage(gifImages[1], 0);
    gifImages[2] = Toolkit.getDefaultToolkit().getImage("blueball.gif");
    mediaTracker.addImage(gifImages[2], 0);
    gifImages[3] = Toolkit.getDefaultToolkit().getImage("yellowball.gif");
    mediaTracker.addImage(gifImages[3], 0);
    gifImages[4] = Toolkit.getDefaultToolkit().getImage("purpleball.gif");
    mediaTracker.addImage(gifImages[4], 0);
    gifImages[5] = Toolkit.getDefaultToolkit().getImage("orangeball.gif");
    mediaTracker.addImage(gifImages[5], 0);

    // Block and wait for all images to
    // be loaded
    try {
      mediaTracker.waitForID(0);
    } catch (InterruptedException e) {
      System.out.println(e);
    } // end catch

    // Base the Frame size on the size
    // of the background image.
    // These getter methods return -1 if
    // the size is not yet known.
    // Insets will be used later to
    // limit the graphics area to the
    // client area of the Frame.
    int width = backGroundImage.getWidth(this);
    int height = backGroundImage.getHeight(this);

    // While not likely, it may be
    // possible that the size isn't
    // known yet.  Do the following
    // just in case.
    // Wait until size is known
    while (width == -1 || height == -1) {
      System.out.println("Waiting for image");
      width = backGroundImage.getWidth(this);
      height = backGroundImage.getHeight(this);
    } // end while loop

    // Display the frame
    setSize(width, height);
    setVisible(true);
    setTitle("Copyright 2001, R.G.Baldwin");

    // Create and start animation thread
    animationThread = new Thread(this);
    animationThread.start();

    // Anonymous inner class window
    // listener to terminate the
    // program.
    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  } // end constructor