-
Notifications
You must be signed in to change notification settings - Fork 2
/
Admin.java
167 lines (154 loc) · 4.63 KB
/
Admin.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package First;
import java.awt.Color;
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.plaf.basic.BasicButtonListener;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import java.awt.Choice;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.ScrollPane;
import java.io.IOException;
import java.net.URL;
import javax.swing.JScrollBar;
/**
* This class is made for administration operations such as searching and adding movies to the database.
* GUI Part of the search part
* @author Isil Irem TEKES
* @version 4.35
*/
public class Admin extends JFrame implements ActionListener {
/**
* variables
*/
JTextField textField;
ImageIcon icon;
JButton btnNewButton;
JPanel panel;
JButton[] add = new JButton[66];
Movies mov;
JScrollPane jScroll;
/**
* include panels buttons and scroll . GUI
*/
public Admin() {
getContentPane().setBackground(Color.PINK);
btnNewButton = new JButton("Search");
btnNewButton.setBounds(315, 0, 109, 23);
btnNewButton.addActionListener(new ActionListener() {
/**
* search button and its action
*/
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource()==btnNewButton)
{
/**
* get text from the text field and search it in movie database
*/
String movie = textField.getText();
try {
mov = API.searchMovie(movie);
int x=0, i=0;
panel.removeAll();
/**
* first check the id and print the results with add button next each of them
*/
for(Movie m : mov.results)
{
m = API.getMovie(m.id);
add[i] = new JButton("ADD");
add[i].setBounds(500,x,120,25);
add[i].addActionListener(Admin.this);
/**
* when u choose ones it change already choosen button "added"
*/
if(Database.getMovieById(m.id)!=null)
{
add[i].setEnabled(false);// able to not choose again
add[i].setText("ADDED");
}
panel.add(add[i]);
/**
* print all results images next to name
*/
icon = new ImageIcon(new URL("http://cf2.imgobject.com/t/p/w92/"+m.poster_path));
icon = new ImageIcon(icon.getImage().getScaledInstance(100,100, java.awt.Image.SCALE_SMOOTH));
JLabel image = new JLabel(icon);
image.setBounds(0,x,100,100);
panel.add(image);
System.out.println(m.original_title);
JLabel name = new JLabel(m.original_title);
name.setBounds(110, x, 500, 20);
panel.add(name);
panel.setPreferredSize(new Dimension(500,x+100));
panel.repaint();
jScroll.revalidate();
repaint();
x+=110;
i++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
getContentPane().setLayout(null);
getContentPane().add(btnNewButton);
/**
* text button for users to enter the name of the films
*/
textField = new JTextField();
textField.setBackground(Color.WHITE);
textField.setBounds(182, 1, 133, 20);
getContentPane().add(textField);
textField.setColumns(10);
/**
* scroll panel for panel to see all films result
*/
JPanel forScroll = new JPanel();
forScroll.setBounds(20,51,647,500);
forScroll.setLayout(new BorderLayout());
getContentPane().add(forScroll);
panel = new JPanel();
panel.setLayout(null);
//panel.setPreferredSize(new Dimension(500,400));
jScroll = new JScrollPane(panel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
//jScroll.setViewportView(panel);
//jScroll.setBounds(20, 51, 647, 500);
//jScroll.setViewportView(panel);
forScroll.add(jScroll,BorderLayout.CENTER);
//forScroll.add(panel, BorderLayout.CENTER);
//panel.setLayout(new BorderLayout(0, 0));
setVisible(true);
setBounds(0, 0, 700, 700);
repaint();
}
@Override
public void actionPerformed(ActionEvent e){
int i=0;
for(i=0;i<mov.results.size();i++)
{
if(e.getSource()==add[i]) {
try {
Database.addMovie(API.getMovie(mov.results.get(i).id));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
add[i].setText("ADDED");
add[i].setEnabled(false);
}
}
}
}