-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResultPage.java
98 lines (81 loc) · 3.5 KB
/
ResultPage.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
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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public class ResultPage extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextArea textArea1;
private JTextArea textArea2;
private JTextArea textArea3;
private JTextArea textArea4;
ArrayList<Rating> recommendations;
public ResultPage(ArrayList<Rating> recommendationsparam) {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
// Centring the window///////////////
Dimension screenSize = new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
Dimension windowSize = new Dimension(getPreferredSize());
int wdwLeft = screenSize.width / 2 - windowSize.width / 2;
int wdwTop = screenSize.height / 2 - windowSize.height / 2;
pack();
setLocation(wdwLeft, wdwTop);
///////////////////////////////////////
recommendations = recommendationsparam;
// JScrollPane scroll1 = new JScrollPane (textArea1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// JScrollPane scroll2 = new JScrollPane (textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// JScrollPane scroll3 = new JScrollPane (textArea3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// JScrollPane scroll4 = new JScrollPane (textArea4, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//
// add(scroll1);
// add(scroll2);
// add(scroll3);
// add(scroll4);
textArea1.setText("");
textArea2.setText("");
textArea3.setText("");
textArea4.setText("");
for(Rating rating : recommendations) {
textArea1.setText(textArea1.getText() + MovieDatabase.getTitle(rating.getItem()) + "\n\n");
textArea2.setText(textArea2.getText() + MovieDatabase.getYear(rating.getItem()) + "\n\n");
textArea3.setText(textArea3.getText() + MovieDatabase.getDirector(rating.getItem()) + "\n\n");
textArea4.setText(textArea4.getText() + MovieDatabase.getGenres(rating.getItem()) + "\n\n");
}
buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
buttonOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
System.exit(0);
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void onCancel() {
// add your code here if necessary
dispose();
}
// public static void main(String[] args) {
// ResultPage dialog = new ResultPage();
// dialog.pack();
// dialog.setVisible(true);
// System.exit(0);
// }
}