Eclipse Indigo bug

时间:2013-04-20 01:43:17

标签: java

我已经运行Eclipse Indigo几个月了,我遇到了一个我似乎无法找到答案的错误。我正在创建一个类似于马里奥,旧塞尔达等的小型2d侧卷轴游戏。

我打算向我的父亲展示我在程序中添加了哪些新功能。我父亲决定不用上楼去看我的电脑上的程序,而是决定使用我不确定的sudo屏幕查看功能。我们之前使用过它,基本上它只是让你看到家里另一台电脑的屏幕(在同一个IP接口上),你也可以使用电脑。

我不想以这种方式向我父亲展示我的节目,所以我告诉他上楼。他做了,从那以后,eclipse将不会在你的程序中显示你的JFrame中的任何图形。它会显示诸如单词(写在屏幕上)之类的内容,但不会显示任何图形。例如您的背景图像,角色或其他任何内容。我是积极的,我的编码并不是一个问题,因为在我爸爸做屏幕查看之前我已经测试过并玩了很多次游戏(我们都在Linux薄荷12,BTW)。

我认为这个错误与屏幕查看有关。

如果我能得到一些帮助,我会很高兴。任何都会很棒。感谢。

- 已经解决了 *

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;
}

}

多德

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();}
            }
}

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();
}

}

1 个答案:

答案 0 :(得分:1)

尽我所知,你没有在框架中添加任何内容。

在用自己的图形替换图形后,我能够让它运行...

enter image description here

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);
            }
        });
    }
}

虽然我只是快速浏览了代码,但我建议您不要使用ImageIcon来加载图片,而是使用ImageIO API。除了支持更多图像格式外,当它无法加载图像时会产生更多错误。

我也会避免使用KeyListener来支持key bindings。它们不会遇到与KeyListener

相同的焦点问题