分配的闪烁图像/提示

时间:2015-01-14 22:36:58

标签: java flicker flashing

//Importing the Legendary Packages of the Almighty Java
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import hsa.Console;

//Let there be code
public class ButtonTest implements MouseListener
//and it was good
{
//are these the global variables? I think sooo!
static Console c;
JButton button;
static boolean staticImgVar;
static BufferedImage yourCharacter;
public static int VayneY;

// Mainly the Main Method
public static void main (String args[])
{
    //Not really sure whats going on here but its necessary
    c = new Console ();
    new ButtonTest ();
    //Taking declaring our yourCharacter (or image)
    yourCharacter = null;
    try
    {
        yourCharacter = ImageIO.read (new File ("Vayne2.png"));
    }

    catch (IOException f)
    {
    }
    //when you put this thing here, it allows the image of your character to remain on the screen after it comes back down following the jumping animation
    staticImgVar = true;
    //Loopception
    do
    {
        int x = 600;
        do
        {
            //pretty much what I wrote on top of the line where I first declared the staticImgVar
            if (staticImgVar == true)
            {
                c.drawImage (yourCharacter, 90, 350, null);
            }
            //draws a square and moves it across the screen until it reaches the end of the screen
            c.setColor (Color.black);
            c.fillRect (x, 400, 50, 50);
            x = x - 9;
            delay (50);
            c.clear ();
        }
        while (x > 0);
    }
    while (true);
} //End of Main class


//Creates our button, puts text on it, and adds a mouse listener which tells the button what to do when it is pressed
public ButtonTest ()
{
    JFrame frame = new JFrame ();
    JPanel panel = new JPanel ();

    button = new JButton ("Jump @ 420");

    panel.add (button);
    frame.getContentPane ().add (panel);
    frame.pack ();
    frame.setVisible (true);

    button.addMouseListener (this);
}


//All the events for the button
public void mousePressed (MouseEvent e)
{

}


public void mouseReleased (MouseEvent e)
{

}


public void mouseEntered (MouseEvent e)
{

}


public void mouseExited (MouseEvent e)
{

}


//Tells our character to jump when the button is pressed. When you set the staticImgVar to false,
//it deletes our static image and uses the image that is jumping. After the jumping animation,
//setting the staticImgVar back to true causes the the static image to reappear.
public void mouseClicked (MouseEvent e)
{
    staticImgVar = false;

    //Going up
    for (VayneY = 350 ; VayneY > 200 ; VayneY -= 1)
    {
        c.drawImage (yourCharacter, 90, VayneY, null);
        delay (1);
    }
    //Coming back down

    for (VayneY = 200 ; VayneY < 350 ; VayneY += 1)
    {
        c.drawImage (yourCharacter, 90, VayneY, null);
        delay (1);
    }
    c.clear ();
    staticImgVar = true;

}


//The delay method for pausing purposes
//Measured in miliseconds

public static void delay (int t)
{
    try
    {
        Thread.sleep (t);
    }


    catch (InterruptedException ex)
    {
        Thread.currentThread ().interrupt ();
    }
  }
} //End of ButtonTest

嗨其他编码员,我的图像一直闪烁,我试图在google上查找要添加的内容以修复它,并且无法找到我理解的解决方案。这些是计算机科学任务的开始部分,它几乎是不可能的游戏/几何破折号,但使用了传说中的联盟角色。如果你们可以给我任何提示,无论是代码方面,设计,想法还是对程序的改进,这都会很棒。还有,闪烁的问题。谢谢:))

0 个答案:

没有答案