我一直在寻找这个问题,但它对我不起作用。
我所做的是我有这样的目录
|-> Games (folder)
|----> GamesCombined.java and classes
|----> games (folder)
|--------> pacman (folder)
|------------> PacmanGame.java and classes
Games.java 内部
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import games.pacman.*;
public class GamesCombined extends JFrame {
private JDesktopPane dsktp = new JDesktopPane();
private JMenuBar menuBar = new JMenuBar();
private JMenu gamesmenu = new JMenu("Games");
private JMenuItem play_pacman = new JMenuItem("Pacman");
public GamesCombined() {
super("Games");
setLayout(null);
Container c = getContentPane();
add(dsktp);
setJMenuBar(menuBar);
menuBar.add(gamesmenu);
gamesmenu.add(play_pacman);
play_pacman.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
//I want to add PacmanGame.java as an InternalFrame of this DesktopPane.
}
});
int frameWidth = 800;
int frameHeight = 850;
setSize(frameWidth, frameHeight);
setLocationRelativeTo(null);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
可能吗?或任何其他在 jdesktoppane 中添加外部类的方法?