我正在尝试为我的java游戏创建分层窗格,在我看过的几个例子中,我使用了getLayeredPane,但未导入。当我尝试做同样的事情时,我得到一个“找不到符号”的错误,我认为这通常意味着某些东西还没有被导入。我在这里做错了什么?
package game.backbone;
import game.background.Background;
import game.character.DrawCha;
import game.character.MoveCha;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JComponent;
import javax.swing.JLayeredPane;
public class Window {
private DrawCha cha;
private MoveCha move;
private JFrame frame;
private Background bg;
public static int SIZE;
public static int w, h;
public void createWindow(String title,int height) {
bg = new Background();
cha = new DrawCha();
move = new MoveCha();
frame = new JFrame();
JLayeredPane lp = new getLayeredPane();
h = height;
w = height;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(w, h);
frame.setTitle(title);
frame.setVisible(true);
frame.setFocusable(true);
frame.addKeyListener(move);
lp.add(cha, new Integer(2));
lp.add(bg, new Integer(1));
}
}
答案 0 :(得分:1)
语句JLayeredPane lp = new getLayeredPane();
不正确。您在方法上调用new。
修改它JLayeredPane lp = new JLayeredPane();
public void createWindow(String title, int height) {
bg = new Background();
cha = new DrawCha();
move = new MoveCha();
frame = new JFrame();
JLayeredPane lp = new JLayeredPane();
h = height;
w = height;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.addKeyListener(move);
lp.add(cha, new Integer(2));
lp.add(bg, new Integer(1));
frame.add(lp);
frame.setSize(w, h);
frame.setTitle(title);
frame.setVisible(true);
}
同时检查你的DrawCha和Background类是否扩展了JInternalFrame。你可以有类似的东西
class DrawCha extends JInternalFrame {
public DrawCha() {
setBounds(50, 50, 100, 100);
setResizable(true);
setClosable(true);
setMaximizable(true);
setTitle("DrawCha");
setVisible(true);
}
}