-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsModel.java
129 lines (115 loc) · 4.09 KB
/
SettingsModel.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
/*
* Last Modified: November 3, 2020
* Author: Shalee (Shahrukh) Qureshi
* Description: This class creates the Model for the SettingsView
*
* Constructor List:
* 1. SettingsModel()
*
* Method List:
* 1. public void setGUI(SettingsView view) = This method sets the GUI for the SettingsView
* 2. public void updateState() = This method updates the state of the program
* 3. public String getPlayerSelection() = This method gets the player selection (game mode) from the Model Class
* 4. public String getPlayerX() = This method returns the Model Class value of playerX
* 5. public String getPlayerO() = This method gets the Model Class value of playerO
* 6. public void performAction(String command) = This method performs an action when a button is clicked
* 7. private void openWeb(String uri) = This method opens a specific URI on the web
*
*/
// Import Statements
import javax.swing.JOptionPane;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class SettingsModel extends Object {
// Instance Variables
private SettingsView view;
private Model model;
private final String github = "https://github.com/ShaleeQureshi";
private final String personalSite = "https://www.squreshi.net/";
private final String youtubeVideo = "https://www.youtube.com/watch?v=6CNw1Y2bHTo&ab_channel=ShaleeQureshi";
/**
* This is the SettingsModel Constructor
*/
public SettingsModel(Model model) {
super();
this.model = model;
} // SettingsModel Constructor
/**
* This method sets the GUI for the SettingsView
*
* @param view
*/
public void setGUI(SettingsView view) {
this.view = view;
} // setGUI Method
/**
* This method updates the state of the program
*/
public void updateState() {
this.view.updateView();
} // updateState Method
/**
* This method gets the player selection (game mode) from the Model Class
*
* @return the model class instance of player selection
*/
public String getPlayerSelection() {
return this.model.getPlayerSelection();
} // getPlayerSelection Method
/**
* This method returns the Model Class value of playerX
*
* @return model class instance of playerX
*/
public String getPlayerX() {
return this.model.getPlayerX();
} // getPlayerX Method
/**
* This method gets the Model Class value of playerO
*
* @return model class instance of playerO
*/
public String getPlayerO() {
return this.model.getPlayerO();
} // getPlayerO Method
/**
* This method performs an action when a button is clicked
*
* @param command
*/
public void performAction(String command) {
// If the GitHub button was clicked the following will occur
if (command == "GitHub") {
this.openWeb(this.github);
}
// If the Website button was clicked the following will occur
else if (command == "Website") {
this.openWeb(this.personalSite);
}
// If the Watch a Video button was clicked the following will occur
else if (command == "Watch a Video") {
this.openWeb(this.youtubeVideo);
}
// NOTE: The usage of else if rather than an else for the final block is because
// it makes it easier to implement other blocks into the selection structure in
// the future
} // performAction Method
// Helper Methods
/**
* This method opens a specific URI on the web
*
* @param uri
*/
private void openWeb(String uri) {
try {
Desktop desktop = Desktop.getDesktop(); // Creating an instance of a Desktop
desktop.browse(new URI(uri)); // Opening the URI on the user's default browswer
} catch (IOException error) {
JOptionPane.showMessageDialog(null, error.getMessage());
} catch (URISyntaxException error) {
JOptionPane.showMessageDialog(null, error.getMessage());
}
} // openWeb Method
} // SettingsModel Class