-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatsPanel.java
More file actions
86 lines (70 loc) · 2.76 KB
/
statsPanel.java
File metadata and controls
86 lines (70 loc) · 2.76 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
import javax.swing.*;
import java.awt.event.*;
public class statsPanel extends JPanel {
private Model model;
private statsFrame frame;
private JTextField textSearch;
private JLabel photo;
private JLabel gold;
private JLabel silver;
private JLabel bronze;
private JLabel level;
private JLabel win_rate;
private JLabel objective_kills_most_in_game;
String userName;
String idNumber;
public statsPanel(Model model, statsFrame frame) {
this.model = model;
this.frame = frame;
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
textSearch = new JTextField("giraffesyo#1652", 20);
add(textSearch);
JButton search = new JButton("Search");
add(search);
search.addActionListener(new ButtonHandler());
JTextField anotherExample = new JTextField("Another example -- > itsTimmy#1684");
add(anotherExample);
//photo = new JLabel("Profile picture");
//add(photo);
gold = new JLabel("Gold Medal");
add(gold);
silver = new JLabel("Silver Medal");
add(silver);
bronze = new JLabel("Bronze Medal");
add(bronze);
level = new JLabel("Level");
add(level);
win_rate = new JLabel("Win Rate");
add(win_rate);
objective_kills_most_in_game = new JLabel("Most Objective Kills in one game");
}
private class ButtonHandler implements ActionListener {
private Data data;
public void actionPerformed(ActionEvent e) {
processName(textSearch.getText());
model.update(userName, idNumber);
data = model.getData();
if(data.isNotFound()){
frame.sendNotification("That name could not be found, sorry.");
}
else {
gold.setText("Gold Medal: " + data.getMedals_gold());
silver.setText("Silver Medal: " + data.getMedals_silver());
bronze.setText("Bronze Medal: " + data.getMedals_bronze());
level.setText("Level: " + data.getLevel());
win_rate.setText("Win Rate: " + data.getWin_rate());
objective_kills_most_in_game.setText("Most Objective Kills in one game: " + data.getObjective_kills_most_in_game());
}
repaint();
}
}
private void processName(String userName) {
if (!userName.contains("#")) {
frame.sendNotification("Name should include battle tag #");
} else {
int separate = userName.indexOf("#");
this.userName = userName.substring(0, separate);
this.idNumber = userName.substring(separate + 1);
}
}
}