-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.java
More file actions
executable file
·116 lines (95 loc) · 3.35 KB
/
View.java
File metadata and controls
executable file
·116 lines (95 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class View extends JPanel implements Observer {
private Model model;
/**
* Create a new View.
*/
public View(Model model) {
// Set up the window.
//this.setTitle("Your program title here!");
this.setMinimumSize(new Dimension(128, 128));
this.setSize(400, 400);
//this.setDefaultCloseOperation(JPanel.EXIT_ON_CLOSE);
// Hook up this observer so that it will be notified when the model
// changes.
this.model = model;
//model.addObserver(this);
//Code taken from sample code file WidgetDemo.java
/*
JMenu menu = new JMenu("File");
for (String s: new String[] {"New", "Load", "Save"})
{
JMenuItem mi = new JMenuItem(s);
mi.addActionListener(menuItemListener);
menu.add(mi);
}
JMenuBar menubar = new JMenuBar();
menubar.add(menu);
this.add(menubar);
*/
setVisible(true);
}
/**
* Update with data from the model.
*/
public void update(Object observable) {
// XXX Fill this in with the logic for updating the view when the model
// changes.
System.out.println("Model changed!");
}
//Code taken from sample code file WidgetDemo.java
public class Widgets {
public void main(String[] args) {
Widgets demo = new Widgets();
}
JLabel label;
//Code taken from sample code file WidgetDemo.java
Widgets()
{
JFrame f = new JFrame("View");
f.setSize(640, 480);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
/*
// create a button and add a listener for events
JButton button = new JButton("My Button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setText("button");
}
});
*/
/*
// create a menu
JMenu menu = new JMenu("File");
// create some menu choices
for (String s: new String[] {"New", "Load", "Save"})
{
// add this menu item to the menu
JMenuItem mi = new JMenuItem(s);
// set the listener when events occur
mi.addActionListener(menuItemListener);
// add this menu item to the menu
menu.add(mi);
}
JMenuBar menubar = new JMenuBar();
menubar.add(menu);
*/
// define the layout
// http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
// add the widgets
//f.add(menubar);
f.setLayout(new FlowLayout());
f.setVisible(true);
}
} //Widgets end
}