We now want to add a new “get book” view that allows the user of the system to check how many books a specific user is borrowing. Create a ViewGetBook class that extends View<ControllerGetBook> and has the following UML specification: +------------------------------------------------+ | ViewGetBook | +------------------------------------------------+ | - t: JTextField | +------------------------------------------------+ | + ViewGetBook(Library m, ControllerGetBook c) | | + update(): void | +------------------------------------------------+ The ViewGetBook shows the text field called t (where the user can type text) and a button. Use a grid layout manager to position the two components
时间: 2023-08-15 07:10:37 浏览: 223
Below is the Java code for the ViewGetBook class that extends View<ControllerGetBook> and has the specified UML specification:
```
import javax.swing.*;
import java.awt.*;
public class ViewGetBook extends View<ControllerGetBook> {
private JTextField t;
public ViewGetBook(Library m, ControllerGetBook c) {
super(m, c);
this.setLayout(new GridLayout(2, 1));
t = new JTextField();
JButton b = new JButton("Get Books");
b.addActionListener(e -> controller.process());
this.add(t);
this.add(b);
this.setSize(300, 100);
this.setVisible(true);
}
public void update() {
JOptionPane.showMessageDialog(this, model.getState());
}
}
```
In this implementation, the constructor sets the layout to a 2x1 grid and creates a JTextField and a JButton. The action listener for the button calls the process() method in the associated controller. The update() method displays a message dialog with the state of the model when called.
阅读全文