学习Java ...为什么这张图片在闪烁/闪烁? [英] Learning java...why on earth is this image flickering/flashing?

查看:306
本文介绍了学习Java ...为什么这张图片在闪烁/闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有很多类似的问题,但是它们实现了不同的代码...这只是基础代码,所以我感觉我在做一些非常奇怪/错误的事情.这就是我的代码的样子. gif可以透明且具有动画效果,如果可以改变的话.

There seem to be a lot of similar problems, but they implement different code...this is just the base code, so I have a feeling I'm doing something very strange/wrong. This is what my code looks like. The gifs are transparent and animated, if that changes things.

import java.awt.*;
import javax.swing.*;
public class NewClass extends JFrame {
    private JLabel label;
    private JButton button;
    private JTextField textfield;
    private ImageIcon image;
    private JLabel label1;
    private ImageIcon imaged;
    private JLabel label2;

    public NewClass (){
        setLayout(new FlowLayout());

        label = new JLabel("Hi, I am a label!");
        add(label);
        image = new ImageIcon(getClass().getResource("sprite15_2_1.gif"));
        label1 = new JLabel(image);
        add(label1);
         imaged = new ImageIcon(getClass().getResource("sprite2_1_1.gif"));
        label2 = new JLabel(imaged);
        add(label2);
        label1.setDoubleBuffered(true);
        label2.setDoubleBuffered(true);
        textfield = new JTextField(15);
        add (textfield);

        button = new JButton("aight");
        add(button);
    }
    public static void main (String args[]){

    NewClass gui = new NewClass();
    gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    gui.pack();
    gui.setVisible(true);
    gui.setTitle("Elan Vital");
    }
}

已编辑以包含完整的代码.这只是一个简单的程序.

Edited to contain full code. It's just a simple program.

闪烁的GIF(sprite15_2_1.gif):

The Flashing GIF (sprite15_2_1.gif) :

sprite_2_1_1.gif显示完美,但sprite15_2_1.gif的下半部分闪烁白色.我不知道我有什么不同:.我已经仔细检查了gif,以确保文件本身没有问题...

sprite_2_1_1.gif shows up perfectly, but the bottom half of sprite15_2_1.gif flickers white. I have no idea what's different I: " . I have double-checked the gif to be sure it's not a problem with the file itself...

推荐答案

gif文件确实存在问题.

There were problems with the gif file indeed.

使用以下任一图像代替您发布的图像.不需要Double buffering.

Use any one of the following image instead of the one you posted. Double buffering is not necessary.

图像已在Photoshop中更正.有一些多余的帧可能已导致闪烁,但令人惊讶的事实是图像在所有图像查看器上都能正确显示,但在Java中却不能.因此可能会出现Java错误.

The image has been corrected in photoshop. There were some redundant frames which may have been causing the flickering but the surprising fact is the image shows correctly on all image viewers but not in Java. So possibility of a java bug.

第一个图像要快一些,第二个图像要慢0.2s.使用任何一个.

The first image is a bit faster, the second one is slower by 0.2s. Use any one.

这篇关于学习Java ...为什么这张图片在闪烁/闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆