현재 내 자신의 지뢰 찾기를 개발 중입니다. 스윙은 모델 - 뷰 - 컨트롤러 디자인 패턴을 따른다. MVC에서 모델에 변화가있을 때마다 을 배웠습니다. 컨트롤러는 그 변화를보기에서 역시 나타냅니다.. 그러나이 예제에서는 setTitle
및 setInfo
의 변경 사항을보기에 반영하는 방법을 추적 할 수 없습니다.Model-View-Controller에서 모델을 변경해야하는 이유는 무엇입니까? 뷰에서 변경이 트리거되지 않습니까?
여기서 대화 상자의 제목을 설정하면 실제 콘텐츠 (모델)가 변경되지만 출력 (보기)에는 해당 변경 사항이 없습니다.
//InfoDisplayer is inner class of class MenuActionListener
class InfoDisplayer extends JDialog {
JLabel info;
BorderLayout infoBorderLayout = new BorderLayout();
public InfoDisplayer(JFrame ownerFrame) {
super(ownerFrame,true);
info = new JLabel();
setFocusable(false);
setSize(300,400);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setLayout(infoBorderLayout);
add(info,BorderLayout.SOUTH);
setVisible(true);
}
void setInfo(JLabel info) {
this.info = info;
}
public void setTitle(String title) {
super.setTitle(title);
}
}
if ((event.getActionCommand()).equals("HowToPlay")) {
InfoDisplayer instructionsDisplay = new InfoDisplayer(gUIManagerFrame);
//gUIManagerFrame is an object of its outer class,MenuActionListener
instructionsDisplay.setTitle("INSTRUCTIONS");
instructionsDisplay.setInfo(new JLabel("<html><h1><B>INSTRUCTIONS</B></h1></html>"));
} else {// if about is clicked!!
InfoDisplayer aboutDisplay = new InfoDisplayer(gUIManagerFrame);
aboutDisplay.setTitle("MineSweeper v0.1");
aboutDisplay.setInfo(new JLabel("<html><h1><B>MineSweeperv1.0</B></h1> </html>"));
}
MVC에 대한 모든 단어는 무엇입니까? –
2 건의 승인 중 어느 것도 작동하지 않았습니다. 어떻게 이전 JLabel을 제거하고 새 JLabel을 추가합니까? \t \t \t \t \t 1 : "무효 setInfo (JLabel의 정보) { \t \t \t \t \t \t 제거 (이.정보); \t \t \t \t \t \t this.info.setText (info.toString()); \t \t \t \t add (this.info, BorderLayout.SOUTH); \t \t \t \t \t} "2 : "\t \t \t \t \t 무효 setInfo (JLabel의 정보) { \t \t \t \t \t \t 제거 (this.info); \t \t \t \t \t \t this.info = info; \t \t \t \t \t add (info, BorderLayout.SOUTH); \t \t \t \t \t}는 "업데이트에 대한 –
+1 이상 교체하십시오. [여기] MVC (http://stackoverflow.com/a/8401255/230513) 죄송 – trashgod