Modify the run method of the GUI class to add a ViewCreate view that uses a ControllerCreate controller and the same model as before (not a new model!) Do not delete the previous views. 写出符合要求的java代码
时间: 2023-12-06 22:39:40 浏览: 111
```
public class GUI {
private Model model;
private JFrame frame;
private JPanel panel;
private JButton button;
public GUI(Model model) {
this.model = model;
this.frame = new JFrame();
this.panel = new JPanel();
this.button = new JButton("Click me");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
model.incrementCounter();
}
});
panel.add(button);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public void run() {
//Original view
View view1 = new View(model);
Controller controller1 = new Controller(model, view1);
view1.setController(controller1);
//New view
ViewCreate view2 = new ViewCreate(model);
ControllerCreate controller2 = new ControllerCreate(model, view2);
view2.setController(controller2);
//Add both views to the panel
panel.setLayout(new GridLayout(2, 1));
panel.add(view1.getComponent());
panel.add(view2.getComponent());
frame.pack();
}
}
```
阅读全文
相关推荐
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![js](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)