1 回答
TA贡献1831条经验 获得超9个赞
class FaceFrame extends JFrame {
private FacePanel myFacePanel;
public FaceFrame(ArrayList<Face> faceListIn, int width, int height) {
setBounds(100, 100, 900, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FacePanel myFacepanel = new FacePanel(faceListIn);
}
}
添加myFacepanel到JFrame可能是一个好的开始......
public FaceFrame(ArrayList<Face> faceListIn, int width, int height) {
setBounds(100, 100, 900, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FacePanel myFacepanel = new FacePanel(faceListIn);
// This might be a good place to start
add(myFacepanel);
}
……下一个问题……
FacePanel(ArrayList<Face> FaceListIn){
setFaceList(FaceList);
}
您分配FaceList给自己(您没有使用FaceListIn)。
我会摆脱static并更新代码......
class FacePanel extends JPanel {
private ArrayList<Face> FaceList;
public void setFaceList(ArrayList<Face> FaceListIn) {
FaceList = FaceListIn;
}
//draw panel
FacePanel() {
super();
}
FacePanel(ArrayList<Face> FaceListIn) {
setFaceList(FaceListIn);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (Face oD : FaceList) {
oD.paintComponent(g);
}
}
}
添加回答
举报