Example #1
1
 private MonopolyToken createToken(String tokenName, int playerId) {
   Image img = new ImageIcon("icons/" + tokenName + ".png").getImage();
   img = img.getScaledInstance(40, 40, Image.SCALE_SMOOTH);
   MonopolyToken token = new MonopolyToken(playerId, new ImageIcon(img));
   token.setBounds(tileLocations[0][0], tileLocations[0][1], 40, 40);
   return token;
 }
  public myImageFade() {
    myImage1 = Toolkit.getDefaultToolkit().getImage("d:/1.jpg");
    myImage2 = Toolkit.getDefaultToolkit().getImage("d:/ball.gif");

    myImage1_scaled = myImage1.getScaledInstance(500, 500, Image.SCALE_FAST);
    myImage2_scaled = myImage2.getScaledInstance(500, 500, Image.SCALE_FAST);
    repaint();

    try {
      MediaTracker mt = new MediaTracker(this);
      mt.addImage(myImage1, 0);
      mt.addImage(myImage2, 0);
      mt.waitForAll();

      PixelGrabber grab1 =
          new PixelGrabber(myImage1, 0, 0, picWidth, picHeight, m_Img1Pix, 0, picWidth);
      PixelGrabber grab2 =
          new PixelGrabber(myImage2, 0, 0, picWidth, picHeight, m_Img2Pix, 0, picWidth);

      grab1.grabPixels();
      grab2.grabPixels();

      System.out.println(m_Img1Pix.length);

      System.out.println(m_Img1Pix[18500]);

      m_ImgSrc = new MemoryImageSource(picWidth, picHeight, m_Pix, 0, picWidth);
      m_ImgSrc.setAnimated(true);
      m_Img = createImage(m_ImgSrc);
    } catch (InterruptedException e) {
    }
  }
  public void getNextHero() {
    anyHero = this.heroManager.getHero();

    ImageIcon icon1 = anyHero.getIcon(0);
    Image image1 = icon1.getImage();
    Image resizedImage1 = image1.getScaledInstance(photo1.getWidth(), photo1.getHeight(), 0);
    photo1.setIcon(new ImageIcon(resizedImage1));

    ImageIcon icon2 = anyHero.getIcon(1);
    Image image2 = icon2.getImage();
    Image resizedImage2 = image2.getScaledInstance(photo2.getWidth(), photo2.getHeight(), 0);
    photo2.setIcon(new ImageIcon(resizedImage2));

    ImageIcon icon3 = anyHero.getIcon(2);
    Image image3 = icon3.getImage();
    Image resizedImage3 = image3.getScaledInstance(photo3.getWidth(), photo3.getHeight(), 0);
    photo3.setIcon(new ImageIcon(resizedImage3));
    // prosarmogh eikonwn sta label

    System.out.println(anyHero.getName());
    // yparxei boithitika gia na fainetai to onoma

    nameArea.setText("");
    // katharizei to textArea

  }
Example #4
0
  // CONSTRUCTOR
  public DrawRooms(int[][] arooms) {
    try {
      image1 = ImageIO.read(new File("tiger.gif"));
      image2 = ImageIO.read(new File("prisoner.gif"));
      image3 = ImageIO.read(new File("princess.jpg"));

    } catch (IOException e) {;
    }
    //		 Image image;

    // THIS WILL ASSIGN A REFERENCE TO ARRAY OF INTS CREATED  IN GUI CLASS
    this.Arooms = arooms;

    // YOU NEED TO SET THE PREFERRED SIZE TO GET THE DISPLAY THE SIZE YOU WANT IT.
    setPreferredSize(new Dimension(620, 620));

    //	  CREATE  THREE  IMAGEICONS E.G. THIS SHOWs HOW TO SCALE IT

    // create the imageicon
    // get an image object from it
    image1 = image1.getScaledInstance(28, 28, Image.SCALE_SMOOTH); // reduce its size
    image2 = image2.getScaledInstance(28, 28, Image.SCALE_SMOOTH); // reduce its size
    image3 = image3.getScaledInstance(28, 28, Image.SCALE_SMOOTH); // reduce its size

    //

    //       setBackground(Color.yellow);

  }
Example #5
0
  /*Add button to master panel*/
  private void addHistoryButton(JFrame frame, JPanel panel) {
    ImageIcon buttonImage = new ImageIcon("assets\\other\\button.png");
    ImageIcon buttonPressedImage = new ImageIcon("assets\\other\\buttonPressed.png");
    // button
    JPanel buttonHolder = new JPanel();
    this.searchButton = new JButton("MATCH HISTORY");
    this.searchButton.setPreferredSize(new Dimension(222, 50));
    this.searchButton.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 10)); // custom font
    this.searchButton.setForeground(Color.WHITE); // text color
    this.searchButton.setBackground(Color.DARK_GRAY);
    this.searchButton.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    this.searchButton.setHorizontalTextPosition(AbstractButton.CENTER);
    // search button background image
    // regular button
    Image tempImage = buttonImage.getImage();
    Image newTempImg = tempImage.getScaledInstance(222, 50, Image.SCALE_SMOOTH);
    buttonImage = new ImageIcon(newTempImg);
    // pressed button
    Image tempImage2 = buttonPressedImage.getImage();
    Image newTempImg2 = tempImage2.getScaledInstance(222, 50, Image.SCALE_SMOOTH);
    buttonPressedImage = new ImageIcon(newTempImg2);
    this.searchButton.setIcon(buttonImage);
    this.searchButton.setRolloverIcon(buttonPressedImage);

    this.searchButton.addActionListener(this);
    buttonHolder.add(this.searchButton);
    buttonHolder.setOpaque(false);
    panel.add(buttonHolder);
  }
Example #6
0
 // set size of the button (inherited from JButton =) )
 // changes the size of the button, and resizes the image to fit it.
 public void setSize(int x, int y) {
   if (!mode.equals("String")) {
     width = x;
     height = x;
     image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
     BWimage = BWimage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
   }
 }
  /**
   * The image we're replacing.
   *
   * @return see desc
   */
  public Image getImage() {
    if (!_loaded && _imageResource.isLoaded()) {
      Image image = ((AWTFSImage) _imageResource.getImage()).getImage();
      if (_doScaleImage && (_targetWidth > 0 || _targetHeight > 0)) {
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        int newW = _targetWidth;
        int newH = _targetHeight;

        if (newW == -1) {
          newW = (int) (w * ((double) newH / h));
        }

        if (newH == -1) {
          newH = (int) (h * ((double) newW / w));
        }

        if (w != newW || h != newH) {
          if (image instanceof BufferedImage) {
            image = ImageUtil.getScaledInstance((BufferedImage) image, newW, newH);
          } else {
            if (true) {
              throw new RuntimeException(
                  "image is not a buffered image! " + _imageResource.getImageUri());
            }
            String scalingType = Configuration.valueFor("xr.image.scale", "HIGH").trim();

            if (scalingType.equalsIgnoreCase("HIGH") || scalingType.equalsIgnoreCase("MID")) {
              image = image.getScaledInstance(newW, newH, Image.SCALE_SMOOTH);
            } else {
              image = image.getScaledInstance(newW, newH, Image.SCALE_FAST);
            }
          }
        }
        _image = image;
      } else {
        _image = image;
      }
      _loaded = true;
      XRLog.load(
          Level.FINE,
          "Icon: replaced image " + _imageResource.getImageUri() + ", repaint requested");
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              repaintListener.repaintRequested(_doScaleImage);
            }
          });
    }

    return _image;
  }
Example #8
0
  /**
   * Gets the image using the specified dimension.
   *
   * @param d The <code>Dimension</code> of the requested image. Rescaling will be performed if
   *     necessary.
   * @return The <code>Image</code> with the required dimension.
   */
  public Image getImage(Dimension d) {
    final Image im = getImage();
    if (im == null || (im.getWidth(null) == d.width && im.getHeight(null) == d.height)) return im;

    synchronized (loadingLock) {
      final Image cached = scaledImages.get(d);
      if (cached != null) return cached;

      MediaTracker mt = new MediaTracker(_c);
      try {
        // Use SCALE_REPLICATE instead of SCALE_SMOOTH to avoid
        // ClassCastException.
        // TODO (perhaps): find a better solution.
        Image scaled = im.getScaledInstance(d.width, d.height, Image.SCALE_REPLICATE);
        mt.addImage(scaled, 0, d.width, d.height);
        mt.waitForID(0);
        int result = mt.statusID(0, false);
        if (result == MediaTracker.COMPLETE) {
          scaledImages.put(d, scaled);
        } else {
          logger.warning("Scaling image: " + getResourceLocator() + " => " + result);
        }
        return scaled;
      } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to scale image: " + getResourceLocator(), e);
      }
    }
    return null;
  }
Example #9
0
 private void addMonopolyImage() {
   Image img = new ImageIcon("icons/monopoly.jpg").getImage();
   img = img.getScaledInstance(700, 700, Image.SCALE_SMOOTH);
   JLabel monopoly = new JLabel(new ImageIcon(img));
   monopoly.setBounds(0, 0, 700, 700);
   add(monopoly);
 }
Example #10
0
  /**
   * Adds a new picture from a card to the display.
   *
   * @param image picture that is to be displayed
   * @return a new label containing the picture
   */
  protected JLabel addNewImageLabel(Image image) {
    // shrink the image to fit cards better on the screen
    Image resizedImage = image.getScaledInstance(66, 103, Image.SCALE_SMOOTH);
    final JLabel imageLabel = new JLabel(new ImageIcon(resizedImage));
    // allow the user to click on and select the card
    imageLabel.addMouseListener(
        new MouseListener() {
          private boolean isInside = false;

          public void mouseClicked(MouseEvent e) {}

          public void mouseEntered(MouseEvent e) {
            isInside = true;
          }

          public void mouseExited(MouseEvent e) {
            isInside = false;
          }

          public void mousePressed(MouseEvent e) {}

          public void mouseReleased(MouseEvent e) {
            if (e.getButton() != MouseEvent.BUTTON1 || !isInside) return;

            setSelectedImageLabel(imageLabel);
          }
        });
    cardImageLabels.add(imageLabel);

    return imageLabel;
  }
Example #11
0
  public VentanaJuego(Canasta c) {
    // tamaño e inicializacion de contenedores
    setSize(1000, 800);
    Image canasta;
    ImageIcon imageIcon = new ImageIcon("src/basketArcade/image/basket_ball_court.jpg");
    canasta = imageIcon.getImage();
    canasta = canasta.getScaledInstance(1000, 800, java.awt.Image.SCALE_SMOOTH);
    this.lCancha = new JPanel();
    this.puntuacion = new JPanel();
    panelPoints = new JPanel();

    lPuntos = new JLabel("0");
    panelPoints.add(lPuntos);
    lCancha.setLayout(null);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    // botones
    pausa = new JButton("Pausa");
    // lista de puntos
    puntuacion.setLayout(new BorderLayout());
    JPanel pane = new JPanel();
    pane.add(pausa);
    puntuacion.add(pane, BorderLayout.NORTH);
    // introduccion de los paneles en en contenedor de la ventana
    getContentPane().add(panelPoints, BorderLayout.WEST);
    getContentPane().add(lCancha, BorderLayout.CENTER);
    getContentPane().add(puntuacion, BorderLayout.EAST);
    pause = false;
    lCancha.add(c.getlCanasta());
    // no se permite redimensionar la ventana
    setResizable(false);
    setVisible(true);
  }
Example #12
0
 private void addBoardImage() {
   Image boardImage = new ImageIcon("assets/referenceBoard.jpg").getImage();
   boardImage = boardImage.getScaledInstance(700, 700, Image.SCALE_SMOOTH);
   JLabel board = new JLabel(new ImageIcon(boardImage));
   board.setBounds(0, 0, 700, 700);
   add(board);
 }
  /*
   * Filminformationen in die GUI Labels schreiben
   */
  private void setMovieDetails() {

    try {
      // Create a URL for the image's location
      URL url = new URL(coverUrl);

      // Get the image
      java.awt.Image image =
          java.awt.Toolkit.getDefaultToolkit().getDefaultToolkit().createImage(url);
      Image imageNewScale = image.getScaledInstance(178, 270, 270);
      ImageIcon cover = new ImageIcon(imageNewScale);
      coverLabel.setIcon(cover);

    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    filmTitelLabel.setText(titel);
    datumLabel.setText("Filmstart: " + filmstart);
    inhaltLabel.setText(inhalt);
    fskAlterLabel.setText("Ab " + fsk + " Jahre");
    genreLabel.setText(genre);
    laengeLabel.setText("Laufzeit: " + laenge + " Min");
    landLabel.setText(land + " " + jahr);
    darstellerLabel.setText(darsteller);
    if (regisseur != null) {
      regisseurLabel.setText("Regie: " + regisseur);
    } else {
      regisseurLabel.setText("Regie: ");
    }

    shadowLabel.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/data/pics/cover_shadow3.png")));
  }
Example #14
0
  /**
   * Constructor de la clase.
   *
   * @param padre ventana principal de la aplicación.
   * @param modal true si mantiene el foco, false de lo contrario.
   * @param imgAdjunto
   * @param gestor
   */
  public DialogAdjunto(
      JFrame padre, boolean modal, Object imgAdjunto, GestorResolucionExamen gestor) {
    super(padre, modal);
    initComponents();
    this.setLocationRelativeTo(null);
    this.getRootPane()
        .registerKeyboardAction(
            new EscapeAction(),
            KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    // Fondo translúcido.
    this.pnlCentral.setBackground(LookAndFeelEntropy.COLOR_BLANCO_TRANSLUCIDO);

    // Para que el undecorated dialog pueda moverse.
    ComponentMover cm = new ComponentMover(JDialog.class, pnlImagen);

    ComponentResizer cr = new ComponentResizer();
    cr.setSnapSize(new Dimension(10, 10));
    cr.registerComponent(this);

    this.gestor = gestor;

    try {
      byte[] bytesImagen = (byte[]) imgAdjunto;
      Image img = Toolkit.getDefaultToolkit().createImage(bytesImagen);
      img.getScaledInstance(250, 250, Image.SCALE_DEFAULT);
      this.pnlImagen.setImagen(img);
    } catch (Exception e) {
    }
  }
 /**
  * 获取缩放过的图像
  *
  * @param _theme 主题
  * @param _filename 文件名
  * @param _width 宽度
  * @return 缩放后的图像
  */
 public static Image getRandomScaledImage(String _theme, String _filename, int _width) {
   Image x = getImage(_theme, _filename);
   Random rand = new Random();
   float r = rand.nextFloat() * 0.5f;
   return x.getScaledInstance(
       (int) (_width * (0.5 + r)), (int) (_width * (0.5 + r)), Image.SCALE_SMOOTH);
 }
  private void scaleImage() {
    width = image.getWidth(this);
    height = image.getHeight(this);
    double ratio = 1.0;

    /*
     * Determine how to scale the image. Since the accessory can expand
     * vertically make sure we don't go larger than 150 when scaling
     * vertically.
     */
    if (width >= height) {
      ratio = (double) (ACCSIZE - 5) / width;
      width = ACCSIZE - 5;
      height = (int) (height * ratio);
    } else {
      if (getHeight() > 150) {
        ratio = (double) (ACCSIZE - 5) / height;
        height = ACCSIZE - 5;
        width = (int) (width * ratio);
      } else {
        ratio = (double) getHeight() / height;
        height = getHeight();
        width = (int) (width * ratio);
      }
    }

    image = image.getScaledInstance(width, height, Image.SCALE_DEFAULT);
  }
Example #17
0
  // 선택된 이미지를 보여줍니다.
  private void image_Show() {

    int row = table_ftp_view.getSelectedRow();
    int col = table_ftp_view.getColumnCount();

    Vector<Object> temp = new Vector<Object>();

    for (int i = 0; i < col; i++) {
      temp.add(dtm.getValueAt(row, i));
    }

    Image image = null;
    try {

      URL url =
          new URL(
              "http://14.38.161.45:7080/"
                  + Server_Config.getFTPMARTPATH()
                  + "/"
                  + temp.get(1)
                  + "."
                  + temp.get(2));
      System.out.println(url.toString());
      image = ImageIO.read(url);
      label_show_image.setIcon(
          new ImageIcon(image.getScaledInstance(250, 250, Image.SCALE_SMOOTH)));
    } catch (IOException e) {
      e.printStackTrace();
    }

    // l.setIcon(new ImageIcon(image.getScaledInstance(150, 150, Image.SCALE_SMOOTH)));
  }
Example #18
0
  public void createGUI() {
    setLayout(new BorderLayout());

    buttonPanel.add(submitButton);
    buttonPanel.setSize(400, 400);
    hostPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    ImageIcon imageIcon = new ImageIcon("images/logo.png"); // load the image to a imageIcon
    Image image = imageIcon.getImage(); // transform it
    Image newimg =
        image.getScaledInstance(600, 120, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
    imageIcon = new ImageIcon(newimg); // transform it back
    JLabel scrabbleLabel = new JLabel(imageIcon, SwingConstants.CENTER);
    add(scrabbleLabel, BorderLayout.NORTH);
    gbc.gridx = 0;
    gbc.gridy = 0;
    hostPanel.add(hostLabel, gbc);
    gbc.gridx = 0;
    gbc.insets = new Insets(46, 0, 46, 0);
    gbc.gridy = 1;
    hostPanel.add(portLabel, gbc);
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.anchor = GridBagConstraints.EAST;
    hostPanel.add(portTF, gbc);
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.gridwidth = 2;
    hostPanel.add(buttonPanel, gbc);
    add(hostPanel, BorderLayout.CENTER);
  }
 /**
  * Renders the image at the proper size into <code>bgImage</code>. This method assumes that <code>
  * bgImage</code> is not <code>null</code>.
  *
  * @param width The width of the volatile image to render into.
  * @param height The height of the volatile image to render into.
  * @param hint The scaling hint to use.
  */
 protected void renderImage(int width, int height, int hint) {
   Image master = getMasterImage();
   if (master != null) {
     do {
       Image i = master.getScaledInstance(width, height, hint);
       tracker.addImage(i, 1);
       try {
         tracker.waitForID(1);
       } catch (InterruptedException e) {
         e.printStackTrace();
         bgImage = null;
         return;
       } finally {
         tracker.removeImage(i, 1);
       }
       bgImage.getGraphics().drawImage(i, 0, 0, null);
       tracker.addImage(bgImage, 0);
       try {
         tracker.waitForID(0);
       } catch (InterruptedException e) {
         e.printStackTrace();
         bgImage = null;
         return;
       } finally {
         tracker.removeImage(bgImage, 0);
       }
     } while (bgImage.contentsLost());
   } // End of if (master!=null).
   else {
     bgImage = null;
   }
 }
Example #20
0
 /**
  * 插入LOGO
  *
  * @param source 二维码图片
  * @param imgPath LOGO图片地址
  * @param needCompress 是否压缩
  * @throws Exception
  */
 private static void insertImage(BufferedImage source, String imgPath, boolean needCompress)
     throws Exception {
   File file = new File(imgPath);
   if (!file.exists()) {
     System.err.println("" + imgPath + " 该文件不存在!");
     return;
   }
   Image src = ImageIO.read(new File(imgPath));
   int width = src.getWidth(null);
   int height = src.getHeight(null);
   if (needCompress) { // 压缩LOGO
     if (width > WIDTH) {
       width = WIDTH;
     }
     if (height > HEIGHT) {
       height = HEIGHT;
     }
     Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH);
     BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     Graphics g = tag.getGraphics();
     g.drawImage(image, 0, 0, null); // 绘制缩小后的图
     g.dispose();
     src = image;
   }
   // 插入LOGO
   Graphics2D graph = source.createGraphics();
   int x = (QRCODE_WIDTH - width) / 2;
   int y = (QRCODE_HEIGHT - height) / 2;
   graph.drawImage(src, x, y, width, height, null);
   Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
   graph.setStroke(new BasicStroke(3f));
   graph.draw(shape);
   graph.dispose();
 }
Example #21
0
    private void paintSprites(List<Sprite> sprites) {

      if (sprites != null) {
        for (int i = 0; i < sprites.size(); i++) {

          // get all sprites with getresource
          URL imagePath = this.getClass().getResource(sprites.get(i).getImageName().toString());
          ImageIcon icon = new ImageIcon(imagePath);
          JLabel picLabel = new JLabel(icon);
          picLabel.setBounds(
              sprites.get(i).getX(),
              sprites.get(i).getY(),
              icon.getIconWidth(),
              icon.getIconHeight());
          this.add(picLabel);
        }

        ImageIcon bgImageIcon =
            new ImageIcon(this.getClass().getResource(controller.getGameModel().getBkgURL()));
        Image reImage = bgImageIcon.getImage();
        reImage =
            reImage.getScaledInstance(
                Dimensions.GAME_MAKER_RIGHT_PANEL_WIDTH,
                Dimensions.GAME_MAKER_RIGHT_PANEL_HEIGHT,
                Image.SCALE_SMOOTH);
        bgImageIcon = new ImageIcon(reImage);
        JLabel bkgImageLabel = new JLabel(bgImageIcon);
        bkgImageLabel.setBounds(
            0,
            Dimensions.GAME_MAKER_RIGHT_PANEL_Y,
            Dimensions.GAME_MAKER_RIGHT_PANEL_WIDTH,
            Dimensions.GAME_MAKER_RIGHT_PANEL_HEIGHT);
        this.add(bkgImageLabel);
      }
    }
 final void initHuman() {
   String sql = "Select * from tblHuman where id = ?";
   try (Connection cn = Tools.getConn();
       PreparedStatement pst = cn.prepareStatement(sql); ) {
     pst.setInt(1, Integer.parseInt(vRow.get(0).toString()));
     ResultSet rs = pst.executeQuery();
     if (rs.next()) {
       txtUserName.setText(rs.getString(2));
       txtBirthDay.setDate(rs.getDate(3));
       txtGender.setText(rs.getString(4));
       txtBirthPlace.setText(rs.getString(5));
       txtNativeCountry.setText(rs.getString(6));
       txtNation.setText(rs.getString(7));
       txtReligion.setText(rs.getString(8));
       txtOccupation.setText(rs.getString(9));
       txtWorkPlace.setText(rs.getString(10));
       txtIDCard.setText(rs.getString(11));
       txtArrivalDate.setDate(rs.getDate(12));
       byte[] b = rs.getBytes(13);
       ImageIcon icon = new ImageIcon(b);
       Image img = icon.getImage();
       img = img.getScaledInstance(lblImage.getWidth(), lblImage.getHeight(), Image.SCALE_SMOOTH);
       lblImage.setIcon(new ImageIcon(img));
       txtRoomID.setText(rs.getString(14));
       txtEmail.setText(rs.getString(15));
     }
   } catch (SQLException ex) {
     Logger.getLogger(EditHumanDialog.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
Example #23
0
  /**
   * Returns a scaled instance of the tile image. Using a MediaTracker instance, this function waits
   * until the scaling operation is done.
   *
   * <p>Internally it caches the scaled image in order to optimize the common case, where the same
   * scale is requested as the last time.
   *
   * @param zo
   * @return Image
   */
  public Image getScaledImage(double zo) {
    Image scaledImage = null;
    if (zo == 1.0) {
      return getImage();
    } else if (zo == zoom && scaledImage != null) {
      return scaledImage;
    } else {
      Image img = getImage();
      //            System.out.println(getWidth());
      if (img != null) {
        scaledImage =
            img.getScaledInstance(
                (int) (getWidth() * zo), (int) (getHeight() * zo), BufferedImage.SCALE_SMOOTH);

        MediaTracker mediaTracker = new MediaTracker(new Canvas());
        mediaTracker.addImage(scaledImage, 0);
        try {
          mediaTracker.waitForID(0);
        } catch (InterruptedException ie) {
          System.err.println(ie);
        }
        mediaTracker.removeImage(scaledImage);
        zoom = zo;
        return scaledImage;
      }
    }

    return null;
  }
Example #24
0
 public WorldView(
     Asteroids<World, Ship, Asteroid, Bullet> game, World world, Ship player1, Ship player2) {
   this.game = game;
   this.facade = game.getFacade();
   this.world = world;
   this.player1 = player1;
   this.player2 = player2;
   this.timer = new Timer(TIMER_DELAY, this);
   setBackground(Color.BLACK);
   ClassLoader loader = WorldView.class.getClassLoader();
   background =
       Toolkit.getDefaultToolkit()
           .getImage(loader.getResource("asteroids/resources/game-background.jpg"));
   background =
       background.getScaledInstance(game.getWidth(), game.getHeight(), Image.SCALE_DEFAULT);
   if (player1 != null) {
     int size = (int) (2 * facade.getShipRadius(player1));
     Image image =
         Toolkit.getDefaultToolkit()
             .getImage(loader.getResource("asteroids/resources/deathstar.png"))
             .getScaledInstance(size, size, Image.SCALE_DEFAULT);
     visualizations.put(player1, new ShipVisualization(Color.RED, player1, image));
   }
   if (player2 != null) {
     int size = (int) (2 * facade.getShipRadius(player2));
     Image image =
         Toolkit.getDefaultToolkit()
             .getImage(loader.getResource("asteroids/resources/sphere.png"))
             .getScaledInstance(size, size, Image.SCALE_DEFAULT);
     visualizations.put(player2, new ShipVisualization(Color.GREEN, player2, image));
   }
   addKeyListener(this);
 }
Example #25
0
  /*
   * Frame Constructor
   */
  public EvalGUI() {

    // map image

    Image img = null;
    try {
      img = ImageIO.read(new File("map2.png"));
    } catch (IOException e) {
    }

    img = img.getScaledInstance(300, 300, Image.SCALE_SMOOTH);

    JLabel small_img = new JLabel(new ImageIcon(img));

    getContentPane().setLayout(new BorderLayout());

    Right_Panel.add(Statistics_Panel, BorderLayout.CENTER);

    Statistics_Panel.add(dist_title);
    Statistics_Panel.add(totaldistance);
    Statistics_Panel.add(dist_curr_obj);
    Statistics_Panel.add(dist_charge);
    Statistics_Panel.add(clean_title);
    Statistics_Panel.add(space_covered);
    Statistics_Panel.add(room_covered);
    Statistics_Panel.add(charge_visits);
    Statistics_Panel.add(battery_title);
    Statistics_Panel.add(batt_remaining);
    Statistics_Panel.add(coverage_title);
    Statistics_Panel.add(nr_coverage_divisions);
    Statistics_Panel.add(vert_hor_div);
    Statistics_Panel.add(rob_coord);
    Statistics_Panel.add(time_elapsed);
    Statistics_Panel.add(time_completion);
    Right_Panel.add(small_img, BorderLayout.SOUTH);

    add(Right_Panel, BorderLayout.EAST);
    add(Map_Panel, BorderLayout.WEST);

    // menu items
    menubar.add(file);
    menubar.add(options);
    menubar.add(exit);
    file.add(newmap);
    options.add(measure);
    options.add(speed);
    exit.add(exit_);
    setJMenuBar(menubar);

    // frame operations
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(860, 650);
    setTitle("EvaluationGUI");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // pack();

  }
Example #26
0
 public WorldMapCellEditor() {
   scrollPane = new JScrollPane();
   scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
   scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
   scrollPane.getViewport().setOpaque(false);
   wmPainter = new WorldMapPainter(worldMap);
   scaledImage = worldMap.getScaledInstance(worldMap.getWidth(null) / 2, -1, Image.SCALE_SMOOTH);
 }
 public static ImageIcon getHalfSizedIcon(String key) {
   ImageIcon icon = getIcon(key);
   Image image = icon.getImage();
   Image half =
       image.getScaledInstance(
           icon.getIconWidth() / 2, icon.getIconHeight() / 2, Image.SCALE_DEFAULT);
   return new ImageIcon(half);
 }
Example #28
0
  private static BufferedImage createWorldMapImage(final Product product) {
    final GeneralPath[] geoBoundaryPaths = ProductUtils.createGeoBoundaryPaths(product);
    final Image wmImage = WorldMapImageLoader.getWorldMapImage(false);
    final WorldMapPainter worldMapPainter =
        new WorldMapPainter(
            wmImage.getScaledInstance(wmImage.getHeight(null) / 2, -1, Image.SCALE_SMOOTH));

    return worldMapPainter.createWorldMapImage(geoBoundaryPaths);
  }
Example #29
0
  private static ImageIcon scaleImage(ImageIcon icon) {
    // Scale it?
    Image img = icon.getImage();
    Image newimg = img.getScaledInstance(444, 200, java.awt.Image.SCALE_SMOOTH);

    ImageIcon newIcon = new ImageIcon(newimg);

    return newIcon;
  }
Example #30
0
  private void resizeImage(String fileName) {
    try {
      Image image = javax.imageio.ImageIO.read(new File(file));
      int imageWidth = image.getWidth(null);
      int imageHeight = image.getHeight(null);

      float scale =
          getRatio(
              imageWidth,
              imageHeight,
              Integer.parseInt(textWidth.getText()),
              Integer.parseInt(textWidth.getText()));
      imageWidth = (int) (scale * imageWidth);
      imageHeight = (int) (scale * imageHeight);

      image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_AREA_AVERAGING);
      // Make a BufferedImage from the Image.
      mBufferedImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = mBufferedImage.createGraphics();

      // Map readeringHint = new HashMap();
      // readeringHint.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
      // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
      // readeringHint.put(RenderingHints.KEY_ANTIALIASING,
      // RenderingHints.VALUE_ANTIALIAS_ON);
      // readeringHint.put(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
      // readeringHint.put(RenderingHints.KEY_DITHERING,
      // RenderingHints.VALUE_DITHER_ENABLE);
      // readeringHint.put(RenderingHints.KEY_INTERPOLATION,
      // RenderingHints.VALUE_INTERPOLATION_BILINEAR);//VALUE_INTERPOLATION_BICUBIC
      // readeringHint.put(RenderingHints.KEY_RENDERING,
      // RenderingHints.VALUE_RENDER_QUALITY);
      // g.setRenderingHints(readeringHint);

      g2.drawImage(image, 0, 0, imageWidth, imageHeight, Color.white, null);

      float[] kernelData2 = {
        -0.125f, -0.125f, -0.125f, -0.125f, 2, -0.125f, -0.125f, -0.125f, -0.125f
      };
      Kernel kernel = new Kernel(3, 3, kernelData2);
      ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
      mBufferedImage = cOp.filter(mBufferedImage, null);
      repaint();
      // file = ImageCompress.getFilePath(file) +
      // ImageCompress.getFileName(file) + "-s." +
      // ImageCompress.getFileExt(file).toLowerCase();
      // FileOutputStream out = new FileOutputStream(file);
      // JPEGEncodeParam param =
      // encoder.getDefaultJPEGEncodeParam(bufferedImage);
      // param.setQuality(0.9f, true);
      // encoder.setJPEGEncodeParam(param);
      // JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
      // encoder.encode(mBufferedImage);
      // out.close();
    } catch (IOException e) {
    }
  }