-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathView.java
58 lines (46 loc) · 1.58 KB
/
View.java
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
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
/**
* @author ashraf
*
*/
public class View {
public View() {
// Create views swing UI components
JTextField searchTermTextField = new JTextField(26);
JButton filterButton = new JButton("Filter");
JTable table = new JTable();
// Create table model
Model model = new Model();
table.setModel(model);
// Create controller
Controller controller = new Controller(searchTermTextField, model);
filterButton.addActionListener(controller);
// Set the view layout
JPanel ctrlPane = new JPanel();
ctrlPane.add(searchTermTextField);
ctrlPane.add(filterButton);
JScrollPane tableScrollPane = new JScrollPane(table);
tableScrollPane.setPreferredSize(new Dimension(700, 182));
tableScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Market Movers",
TitledBorder.CENTER, TitledBorder.TOP));
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, ctrlPane, tableScrollPane);
splitPane.setDividerLocation(35);
splitPane.setEnabled(false);
// Display it all in a scrolling window and make the window appear
JFrame frame = new JFrame("Swing MVC Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(splitPane);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}