final project q7
This commit is contained in:
36
finalproject/Question7/ViewSimple.java
Normal file
36
finalproject/Question7/ViewSimple.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
|
||||
* Date: 2022-04-25
|
||||
*/
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class ViewSimple extends JFrame implements ModelListener {
|
||||
private Library m;
|
||||
private ControllerSimple c;
|
||||
private JLabel label;
|
||||
|
||||
public ViewSimple(Library m, ControllerSimple c) {
|
||||
this.m = m;
|
||||
this.c = c;
|
||||
|
||||
// window
|
||||
this.setTitle("View Simple");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setSize(300, 200);
|
||||
|
||||
m.addListener(this);
|
||||
|
||||
// component
|
||||
label = new JLabel("Total number of borrowed books: " + m.totalBorrowedBooks());
|
||||
add(label);
|
||||
|
||||
// final
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
label.setText("Total number of borrowed books: " + m.totalBorrowedBooks());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user