Java Code Examples for javax.swing.ImageIcon#getImage()

The following examples show how to use javax.swing.ImageIcon#getImage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cardumen_0077_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns the JFreeChart logo (a picture of a gorilla).
 *
 * @return The JFreeChart logo.
 */
public Image getLogo() {

    Image logo = super.getLogo();
    if (logo == null) {
        URL imageURL = this.getClass().getClassLoader().getResource(
                "org/jfree/chart/gorilla.jpg");
        if (imageURL != null) {
            ImageIcon temp = new ImageIcon(imageURL);  
                // use ImageIcon because it waits for the image to load...
            logo = temp.getImage();
            setLogo(logo);
        }
    }
    return logo;

}
 
Example 2
Source File: ImageValidator.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Validates if the image is one of the following types: jpg, png, gif.
 * 
 * @param imageData
 * @param contentType
 * @throws ValidationException
 *             Is thrown if the image data is not of the expected type.
 */
public static void validateImageType(byte[] imageData, String contentType)
        throws ValidationException {

    if (contentType == null || contentType.length() == 0) {
        throw new ValidationException(ReasonEnum.IMAGE_TYPE, "image type",
                null);
    }

    final ImageIcon image = new ImageIcon(imageData);
    if (image.getImage() == null) {
        throw new ValidationException(ReasonEnum.IMAGE_TYPE,
                "image format", null);
    }

    if (!contentType.equalsIgnoreCase("image/jpeg")
            && !contentType.equalsIgnoreCase("image/jpg")
            && !contentType.equalsIgnoreCase("image/pjpeg")
            && !contentType.equalsIgnoreCase("image/png")
            && !contentType.equalsIgnoreCase("image/x-png")
            && !contentType.equalsIgnoreCase("image/gif")) {
        throw new ValidationException(ReasonEnum.IMAGE_TYPE, "image type",
                new Object[] { contentType });
    }

}
 
Example 3
Source File: MessageWindow.java    From javagame with MIT License 6 votes vote down vote up
public MessageWindow(Rectangle rect) {
    this.rect = rect;

    innerRect = new Rectangle(
            rect.x + EDGE_WIDTH,
            rect.y + EDGE_WIDTH,
            rect.width - EDGE_WIDTH * 2,
            rect.height - EDGE_WIDTH * 2);

    textRect = new Rectangle(
            innerRect.x + 16,
            innerRect.y + 16,
            320,
            120);
    
    // ���b�Z�[�W�G���W�����쐬
    messageEngine = new MessageEngine();

    // �J�[�\���C���[�W�����[�h
    ImageIcon icon = new ImageIcon(getClass().getResource("image/cursor.gif"));
    cursorImage = icon.getImage();
    
    timer = new Timer();
}
 
Example 4
Source File: JGenProg2015_000_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns the JFreeChart logo (a picture of a gorilla).
 *
 * @return The JFreeChart logo.
 */
public Image getLogo() {

    Image logo = super.getLogo();
    if (logo == null) {
        URL imageURL = this.getClass().getClassLoader().getResource(
                "org/jfree/chart/gorilla.jpg");
        if (imageURL != null) {
            ImageIcon temp = new ImageIcon(imageURL);  
                // use ImageIcon because it waits for the image to load...
            logo = temp.getImage();
            setLogo(logo);
        }
    }
    return logo;

}
 
Example 5
Source File: GraphicUtils.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * Returns a scaled down image if the height or width is smaller than the
    * image size.
    * 
    * @param icon
    *            the image icon.
    * @param newHeight
    *            the preferred height.
    * @param newWidth
    *            the preferred width.
    * @return the icon.
    */
   public static ImageIcon scaleImageIcon(ImageIcon icon, int newHeight,
    int newWidth) {
Image img = icon.getImage();
int height = icon.getIconHeight();
int width = icon.getIconWidth();

if (height > newHeight) {
    height = newHeight;
}

if (width > newWidth) {
    width = newWidth;
}
img = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
return new ImageIcon(img);
   }
 
Example 6
Source File: MessageWindow.java    From javagame with MIT License 6 votes vote down vote up
public MessageWindow(Rectangle rect) {
    this.rect = rect;

    innerRect = new Rectangle(
            rect.x + EDGE_WIDTH,
            rect.y + EDGE_WIDTH,
            rect.width - EDGE_WIDTH * 2,
            rect.height - EDGE_WIDTH * 2);

    textRect = new Rectangle(
            innerRect.x + 16,
            innerRect.y + 16,
            320,
            120);
    
    // ���b�Z�[�W�G���W�����쐬
    messageEngine = new MessageEngine();

    // �J�[�\���C���[�W�����[�h
    ImageIcon icon = new ImageIcon(getClass().getResource("image/cursor.gif"));
    cursorImage = icon.getImage();
    
    timer = new Timer();
}
 
Example 7
Source File: Alien.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �C���[�W�����[�h����
 *  
 */
private void loadImage() {
    // �G�C���A���̃C���[�W��ǂݍ���
    // ImageIcon���g����MediaTracker���g��Ȃ��Ă���
    ImageIcon icon = new ImageIcon(getClass()
            .getResource("image/alien.gif"));
    image = icon.getImage();

    // ���ƍ������Z�b�g
    width = image.getWidth(panel);
    height = image.getHeight(panel);
}
 
Example 8
Source File: Beam.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �C���[�W�����[�h����
 *  
 */
private void loadImage() {
    ImageIcon icon = new ImageIcon(getClass().getResource("image/beam.gif"));
    image = icon.getImage();

    // ���ƍ������Z�b�g
    width = image.getWidth(panel);
    height = image.getHeight(panel);
}
 
Example 9
Source File: AnimatedPanel.java    From qmcflactomp3 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Cr茅e un panneau anim茅 contenant l'image pass茅e en param猫tre. L'animation
 * ne d茅marre que par un appel 脿 start().
 *
 * @param message Le message 脿 afficher
 * @param icon L'image 脿 afficher et 脿 animer
 * @author Romain Guy
 */
public AnimatedPanel(String message, ImageIcon icon) {
    this.message = message;
    this.font = getFont().deriveFont(14.0f);

    Image image = icon.getImage();
    originalImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    convolvedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics g = originalImage.createGraphics();
    g.drawImage(image, 0, 0, this);
    g.dispose();

    setBrightness(1.0f);
    setOpaque(false);
}
 
Example 10
Source File: Map.java    From javagame with MIT License 4 votes vote down vote up
private void loadImage() {
    // �}�b�v�`�b�v�̃C���[�W�����[�h
    ImageIcon icon = new ImageIcon(getClass().getResource("image/mapchip.gif"));
    chipImage = icon.getImage();
}
 
Example 11
Source File: Chara.java    From javagame with MIT License 4 votes vote down vote up
private void loadImage(String filename) {
    ImageIcon icon = new ImageIcon(getClass().getResource(filename));
    image = icon.getImage();
}
 
Example 12
Source File: Map.java    From javagame with MIT License 4 votes vote down vote up
/**
 * �C���[�W�����[�h����
 */
private void loadImage() {
    ImageIcon icon = new ImageIcon(getClass().getResource("image/block.gif"));
    blockImage = icon.getImage();
}
 
Example 13
Source File: Chara.java    From javagame with MIT License 4 votes vote down vote up
private void loadImage() {
    // �L�����N�^�[�̃C���[�W�����[�h
    ImageIcon icon = new ImageIcon(getClass().getResource("image/chara.gif"));
    charaImage = icon.getImage();
}
 
Example 14
Source File: Map.java    From javagame with MIT License 4 votes vote down vote up
private void loadImage() {
    // �}�b�v�`�b�v�̃C���[�W�����[�h
    ImageIcon icon = new ImageIcon(getClass().getResource("image/mapchip.gif"));
    chipImage = icon.getImage();
}
 
Example 15
Source File: Chara.java    From javagame with MIT License 4 votes vote down vote up
private void loadImage(String filename) {
    ImageIcon icon = new ImageIcon(getClass().getResource(filename));
    image = icon.getImage();
}
 
Example 16
Source File: Chara.java    From javagame with MIT License 4 votes vote down vote up
private void loadImage() {
    // �L�����N�^�[�̃C���[�W�����[�h
    ImageIcon icon = new ImageIcon(getClass().getResource("image/chara.gif"));
    charaImage = icon.getImage();
}
 
Example 17
Source File: Chara.java    From javagame with MIT License 4 votes vote down vote up
private void loadImage() {
    // �L�����N�^�[�̃C���[�W�����[�h
    ImageIcon icon = new ImageIcon(getClass().getResource("image/chara.gif"));
    charaImage = icon.getImage();
}
 
Example 18
Source File: MainPanel.java    From javagame with MIT License 4 votes vote down vote up
/**
 * �u���b�N�̃C���[�W�����[�h
 * 
 * @param filename
 */
private void loadImage(String filename) {
    // �u���b�N�̃C���[�W��ǂݍ���
    ImageIcon icon = new ImageIcon(getClass().getResource(filename));
    blockImage = icon.getImage();
}
 
Example 19
Source File: Sprite.java    From javagame with MIT License 4 votes vote down vote up
/**
 * �C���[�W�����[�h����
 * @param filename �C���[�W�t�@�C����
 */
private void loadImage(String filename) {
    ImageIcon icon = new ImageIcon(getClass().getResource(
            "image/" + filename));
    image = icon.getImage();
}
 
Example 20
Source File: Chara.java    From javagame with MIT License 4 votes vote down vote up
private void loadImage(String filename) {
    ImageIcon icon = new ImageIcon(getClass().getResource(filename));
    image = icon.getImage();
}