2016-08-01 3 views
0

MVC 아키텍처를 사용하여 Java SWING에서 응용 프로그램을 작성하려고하지만이를 수행하는 방법을 모르기 때문에 다중 컨트롤러를 사용하는 데 문제가 있습니다.MVC Java Swing qestion

public class Application { 

public static void main(String[] args) { 
    Application app = new Application(); 
    app.Start(); 

} 
public void Start() 
{ 

    MainModel model = new MainModel(); 
    MainView view = new MainView(); 
    MainController controller = new MainController(view,model); 
    view.setVisible(true); 
}} 

MainController :

public class MainController { 

private MainView theView; 
private MainModel theModel; 

public MainController(MainView theView, MainModel theModel) 
{ 
    this.theModel = theModel; 
    this.theView = theView; 

}} 

MAINVIEW : 모델이 지금 비어 있기 때문에

public class MainView extends JFrame{ 
private JMenu menu = new JMenu(); 

public MainView() 
{ 
    JPanel panel = new JPanel(); 

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    this.setSize(800,800); 
    panel.add(menu); 

    this.add(panel); 
}} 

내가 여기에 넣지 마십시오.

좋아, 그래서 어떻게 여러 컨트롤러를 사용할지 모르겠다. 예 : 새 컨트롤러 UserController를 만들고 싶습니다. 이것을 구현하는 방법을 모르겠습니다. MainController에 새 컨트롤러를 작성해야합니까? MainController에서 UserController를 어떻게 만드나요?

+1

[* 올바르게 MVC의 자바 스윙을 사용하여 GUI 개발 패턴 * 구현 (HTTP를 : //stackoverflow.com/q/25502552/230513)는 "모든 상호 작용이 애플리케이션의 컨트롤러를 통과해야하는 것은 아닙니다."라고 제안합니다. – trashgod

답변

0

MainController를 추가 한 Application 클래스에서 UserController를 작성하기 만하면됩니다.

예 : 2 개의 버튼이있는 경우 actionlistener를 추가 할 수 있습니다.

Button1을가 UserController.doSomething();

Button2를 당신이 그것을 사용하는 방법 그게 MainController.doSomeOtherThings();

할 것 할 것)