-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserPage.java
195 lines (181 loc) · 6.36 KB
/
UserPage.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.*;
import java.util.ArrayList;
import java.util.LinkedList;
/**
* Associated logic class for UserPage.form.
* Displays the available artists music radios.
*/
public class UserPage {
//Class variables
private JList radioList;
private JPanel userPanel;
private JButton trippieReddButton;
private JButton lilUziVertButton1;
private JButton juiceWrldButton;
private JButton XXXButton;
private JButton loFiHipHopButton;
private JButton lilPeepButton;
private JButton goBackButton;
private JLabel botLeft;
private JLabel botMid;
private JLabel botRight;
private JLabel topLeft;
private JLabel topMid;
private JLabel topRight;
private JLabel selectLabel;
private JPanel backPanel;
private JPanel otherPanel;
private JPanel otherPanel2;
private JPanel otherPanel3;
private JPanel otherPanel4;
private JButton backToHomePageButton;
private JTable artist_table;
private JButton saveButton;
private String value;
private PreparedStatement myStmt;
private Statement st;
private Connection myConn;
private ResultSet myRs;
private String url;
private String query;
private JFrame frame2;
private Statement myStmt2;
private ResultSet myRs2 = null;
private String url2;
private int urlIndex;
/**
* Constructor for the UserPage class.
* Creates UserPage panel. Display when called.
*/
public UserPage() throws SQLException {
frame2 = new JFrame("Find your favorite artists!");
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.setSize(800, 700);
userPanel.setBackground(Color.black);
topLeft.setBackground(Color.black);
topMid.setBackground(Color.black);
topRight.setBackground(Color.black);
otherPanel.setBackground(Color.black);
botMid.setBackground(Color.black);
botLeft.setBackground(Color.black);
botRight.setBackground(Color.black);
otherPanel2.setBackground(Color.black);
otherPanel3.setBackground(Color.black);
otherPanel4.setBackground(Color.black);
backPanel.setBackground(Color.black);
frame2.setVisible(true);
frame2.add(userPanel);
/**
* ActionListener for GoBack button.
* Returns back to HomePage, deletes UserPage instance.
*/
goBackButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame2.dispose();
try {
new HomePage();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
});
/**
* ActionListener for trippieReddButton button.
* Opens corresponding URL for correct artist.
*/
trippieReddButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openCorrespondingButton(1);
}
});
/**
* ActionListener for lilUziVertButton button.
* Opens corresponding URL for correct artist.
*/
lilUziVertButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openCorrespondingButton(2);
}
});
/**
* ActionListener for juiceWrldButton button.
* Opens corresponding URL for correct artist.
*/
juiceWrldButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openCorrespondingButton(3);
}
});
/**
* ActionListener for lilPeepButton button.
* Opens corresponding URL for correct artist.
*/
lilPeepButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openCorrespondingButton(4);
}
});
/**
* ActionListener for loFiHipHopButton button.
* Opens corresponding URL for correct artist.
*/
loFiHipHopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openCorrespondingButton(5);
}
});
/**
* ActionListener for XXXButton button.
* Opens corresponding URL for correct artist.
*/
XXXButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openCorrespondingButton(7);
}
});
}
/**
* Opens up for the correct artist Stream.
* @param urlIndex the index of the URL in the DB.
*/
public void openCorrespondingButton(int urlIndex) {
int urlToUse = urlIndex;
try {
//Establish connection to DB
Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/url_info",
"student", "student");
//Create query and execute for hip correct URL from DB
String query = "SELECT * from urls WHERE idurls = " + urlIndex;
myStmt2 = myConn.createStatement();
myRs2 = myStmt2.executeQuery(query);
//See if RS returns anything and get info based on it.
while (myRs2.next()) {
url = myRs2.getString(3);
}
//Open url link in browser
Desktop d = Desktop.getDesktop();
d.browse(new URI(url));
} catch (SQLException | URISyntaxException | IOException ex) {
ex.printStackTrace();
}
};
}