我遇到了 Eclipse 的问题,它没有从我计算机上的 java 代码打开 JFrame,但它在我朋友的计算机上工作,我该怎么办?(它也没有显示任何错误)
这是创建 JFrame 的文件:
package frame;
import java.awt.BorderLayout;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import javax.swing.Timer;
import java.util.ArrayList;
import javax.swing.*;
public class Design implements KeyListener {
private JFrame mainFrame;
private Theme theme;
private ImageMario mario;
boolean right=false;
boolean left=false;
boolean up=false;
boolean down=false;
private ArrayList<String> keys = new ArrayList<String>();
public int counterLoads;
private ArrayList<Integer> relief;
private Timer timer;
public Design(ArrayList<Integer> rel, int minutes){
this.timer = new Timer(minutes*60000, new TimeEnd(this));
this.relief =rel;
this.mario = new ImageMario(100,770, this.relief);
this.mainFrame = new JFrame("Super Mario Bros");
this.mainFrame.setFocusable(true);
this.mainFrame.addKeyListener(this);
this.theme = new Theme(relief, 3000);
this.theme.setLayout(new BorderLayout());
this.mainFrame.setContentPane(this.theme);
this.mainFrame.getContentPane().add(this.mario);
this.mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.mainFrame.setSize(1440, 830);;
this.mainFrame.setVisible(true);
}
}
这是主要功能所在的文件:
import java.util.ArrayList;
import frame.Design;
import frame.ImageRelief;
public class SuperMarioBros{
public static void main(String[] args){
ImageRelief r = new ImageRelief(3000);
ArrayList<Integer> relief = r.generateRelief();
new Design(relief, 3);
}
}
这是主题文件:
package frame;
import java.awt.*;
import java.awt.Image;
import java.util.ArrayList;
import javax.swing.*;
public class Theme extends JPanel {
private ArrayList<Integer> rel;
private int km;
private Image img = new ImageIcon(this.getClass().getResource("/Images/ground.png")).getImage();
private Image bg = new ImageIcon(this.getClass().getResource("/Images/background.jpg")).getImage();
public Theme(ArrayList<Integer> r, int k){
this.rel = r;
this.km = k;
}
public void paintComponent(Graphics g) {
int i=0;
g.drawImage(this.bg, 0, 0, getWidth(), getHeight(), this);
while (i < this.km){
g.drawImage(this.img, i, this.rel.get(i/100), 100, 220, this);
i +=100;
}
}
}
谢谢 !