简体   繁体   English

Eclipse Indigo错误

[英]Eclipse Indigo bug

I have been running Eclipse Indigo for a few months now, and I have run into a bug that I cannot seem to find an answer to. 我已经运行Eclipse Indigo几个月了,但是遇到了一个似乎找不到答案的错误。 I am creating a small 2d side-scroller game similar to that of mario, the old zelda, etc. 我正在创建一个类似于马里奥,旧塞尔达等的小型2D侧滚动游戏。

I was going to show a my dad what new feature I had added into my program. 我要向我的父亲展示我在程序中添加了哪些新功能。 Instead of coming upstairs to see my program on my computer, my dad decided that he could get into it using a sudo screen-viewing thing that I am not sure of. 我父亲没有上楼在计算机上查看我的程序,而是决定可以使用我不确定的sudo屏幕查看工具进入该程序。 We have used this before, and basically all it does is let you see the screen of another computer in your home (on the same IP interface), and you can use the computer too. 以前我们已经使用过此功能,基本上它所做的就是让您看到家中另一台计算机的屏幕(在同一IP接口上),并且您也可以使用该计算机。

I didn't want to show my program to my dad this way, so I told him to come upstairs. 我不想以这种方式向父亲展示我的节目,所以我告诉他上楼。 He did, and ever since then, eclipse will not show any graphics inside of your JFrame in your program. 他做到了,从那时起,eclipse不会在您的程序的JFrame中显示任何图形。 It will show things such as words (written on the screen), but will not show ANY graphics. 它会显示诸如单词(写在屏幕上)之类的内容,但不会显示任何图形。 Such as your background image, or your character, or anything else. 例如您的背景图片,您的角色或其他任何内容。 I am POSITIVE that it isn't some problem with my coding, because I had tested and played the game quite a few times before my dad did the screen-viewing thing (we are both on linux mint 12, BTW). 我很积极地认为我的编码没有问题,因为我在父亲进行屏幕查看之前(我俩都在linux mint 12上)测试并玩了好几次游戏。

I think that this bug is related to the screen-viewing thing. 我认为此错误与屏幕查看有关。

I would love it if I could get some help. 如果可以得到帮助,我会很乐意。 any would be great. 任何都会很棒。 Thanks. 谢谢。

-This has been solved * -这已经解决 *

Board

package External;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.*;

public class Board extends JPanel implements ActionListener, Runnable { 
    Dude p; 
    Image img;    
    Timer time;
    int v = 172;
    Thread animator;

    boolean a = false;
    boolean done2 = false;

    public Board() {
        p = new Dude();
        addKeyListener(new AL());
        setFocusable(true);
        ImageIcon i = new ImageIcon ("/home/clark/Desktop/Swindle_test_background.png");
        img = i.getImage(); 
        time = new Timer (3, this);
        time.start();
    }

    public void actionPerformed(ActionEvent e) {
        p.move();
        repaint(); 
    }
    public void paint(Graphics g) {
        if (p.dy == 1 && done2 == false)
        {
            done2 = true;
            animator = new Thread(this);
            animator.start();
        }
        super.paint(g);
            Graphics2D g2d = (Graphics2D) g;
    if ((p.getX() - 590) % 2400 == 0)
        p.nx = 0;    
    if ((p.getX() - 1790) % 2400 == 0)
        p.nx2 = 0;
            g2d.drawImage(img, 985-p.nx2, 0, null);
            if (p.getX() >= 921)
            g2d.drawImage(img, 985-p.nx, 0, null);
            g2d.drawImage(p.getImage(), 75, v, null);


    }

    private class AL extends KeyAdapter {
        public void keyReleased(KeyEvent e) {
            p.keyReleased(e);
        }
        public void keyPressed(KeyEvent e) {
            p.keyPressed(e);
        }

    }
    boolean h = false;
    boolean done = false;

    public void cycle() {
        if (h == false)
                v--;
        if (v == 125)
                h = true;
        if (h == true && v <= 172 ) {
                v++;
        if (v == 172) {
                    done = true;

        }
    }
}




    public void run() {

        long beforeTime, timeDiff, sleep;

        beforeTime = System.currentTimeMillis();

        while (done == false) {

                cycle();

                timeDiff = System.currentTimeMillis() - beforeTime;
                sleep = 10 - timeDiff;

                if (sleep < 0)
                        sleep = 2;
                try {
                        Thread.sleep(sleep);
                } catch (InterruptedException e) {
                        System.out.println("interrupted");
                }

                beforeTime = System.currentTimeMillis();
        }
        done = false;
        h = false;
        done2 = false;
}

}

Dude 杜德

package External;

import java.awt.Image;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;

public class Dude {
    int x, dx, y, nx2, nx, dy;
    Image Swindle_Man_Right;
    ImageIcon r = new ImageIcon("/home/clark/Desktop/Swindle_Man_Right.png");
    ImageIcon l = new ImageIcon("/home/clark/Desktop/Swindle_Man_Left.png");
    ImageIcon j = new ImageIcon("/home/clark/Desktop/Swindle_Man_Jump.png");

    public Dude() {
        Swindle_Man_Right = l.getImage();
        x = 75;
        nx2 = 685;
        nx = 0;
        y = 172;

}


public void move() {
    x = x + dx;
    nx2 = nx2 + dx;
    nx = nx + dx;
}
public int getX() {
    return x;
}
public int getY() {
    return y;
}

public Image getImage() {
    return Swindle_Man_Right;
}

public void keyPressed(KeyEvent e) {
    int key = e.getKeyCode();
    if (key == KeyEvent.VK_LEFT)
    {               dx = -1;
    Swindle_Man_Right = l.getImage();
            }
    if (key == KeyEvent.VK_RIGHT)
            {dx = 1;
    Swindle_Man_Right = r.getImage();  
            }

    if (key == KeyEvent.VK_UP)
            {dy = 1;
            Swindle_Man_Right= j.getImage();
            }                       }

public void keyReleased(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT)
            dx = 0;

    if (key == KeyEvent.VK_RIGHT)
            dx = 0;

    if (key == KeyEvent.VK_UP)
            {dy = 0;
            Swindle_Man_Right= r.getImage();}
            }
}

Frame

package External;

import javax.swing.*;

public class Frame {

    public Frame() {
        JFrame frame = new JFrame("Swindle [version 0.1.9]");  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(700,390); 
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        new Frame();
}

}

As near as I can tell, you've not added anything to the frame. 据我所知,您尚未在框架中添加任何内容。

After I replaced the graphics with my own, I was able to get it running... 用我自己的图形替换图形后,我就可以运行它了...

在此处输入图片说明

public class Frame {

    public static void main(String[] args) {
        new Frame();
    }

    public Frame() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                }

                JFrame frame = new JFrame("Swindle [version 0.1.9]");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                // This is kind of important...
                frame.add(new Board());

                frame.setSize(700, 390);
                frame.setResizable(false);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }
}

While I've only given the code quick glance, I would recommend that you don't use ImageIcon to load you images and instead use the ImageIO API . 尽管只看了一下代码,但我建议您不要使用ImageIcon加载图像,而应使用ImageIO API Apart from supporting more image formats, it will throw more errors when it can't load the images. 除了支持更多图像格式外,当它无法加载图像时还会引发更多错误。

I would also avoid using KeyListener in favor of key bindings . 我也将避免使用KeyListener来支持键绑定 They don't suffer from the same focus issues as KeyListener 他们没有像KeyListener一样遭受焦点问题的困扰

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM