我遇到以下代码问题。
public class Simulation extends Thread{
private Map map;
private Camera camera;
private JPanel container;
public Simulation(Map map){
this.map = map;
camera = new Camera(map);
container = new JPanel();
container.setLayout(new FlowLayout());
container.add(camera);
}
public JPanel getSimView(){ //I WANT THIS TO RETURN CONTAINER WITH CAMERA ADDED TO, INSTEAD OF CAMERA ITSELF
return camera;
}
类模拟在构建时创建JPanel。然后JFrame调用getSimView()来获取JPanel。
如果getSimView()返回Camera相机(Camera是JPanel的子类),它可以正常工作。
但是当我尝试返回添加了相机的JPanel容器时(如评论所示),框架上没有显示任何内容。