-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuController.java
80 lines (73 loc) · 3 KB
/
MenuController.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
//Samuel Shiau wbd992
//This class contains the event handlers, message displays, and more
package application;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javafx.scene.Node;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.fxml.Initializable;
import java.util.Random;
import java.util.HashMap;
import java.util.Properties;
import java.util.ResourceBundle;
import java.net.URL;
public class MenuController implements Initializable {
@FXML
private AnchorPane PaneP;
@FXML
private AnchorPane PaneVRC;
@FXML
private Text messageD;
@FXML
private Text timeD;
@FXML //will open the posting interface when the button is clicked
public void clickPost(ActionEvent event)throws IOException {
PaneP=FXMLLoader.load(getClass().getResource("Post.fxml")); //get resource
Scene scP=new Scene(PaneP);
Stage winP=(Stage) ((Node)event.getSource()).getScene().getWindow();
winP.setScene(scP);
winP.show(); //show the stage
}
@FXML // will open the view react and comment interface when the button is clicked
public void clickViewReactComment(ActionEvent event)throws IOException{
PaneVRC=FXMLLoader.load(getClass().getResource("ViewReactComment.fxml")); //get resource
Scene scVRC=new Scene(PaneVRC);
Stage winVRC=(Stage) ((Node)event.getSource()).getScene().getWindow();
winVRC.setScene(scVRC);
winVRC.show(); // show the stage
}
// this method will run when the menu interface is opened, it will display the message and the timer
public void initialize(URL location, ResourceBundle resources) {
Random rand=new Random();
try {
HashMap<String,String> messageMap=new HashMap<String,String>();
Properties MessageP=new Properties(); // create property object
File messageF=new File("Messages.properties"); // file object
FileInputStream fileM=new FileInputStream(messageF);
MessageP.load(fileM); // load the info into the object
for(String key:MessageP.stringPropertyNames()) { // put the info into the hashmap
String quote=MessageP.getProperty(key);
messageMap.put(key,quote);
}
int ranKey=rand.nextInt(29)+1; // get random values from 1-30
String ranKeystr=Integer.toString(ranKey);
String display=messageMap.get(ranKeystr); // get the string to display
messageD.setText(display); // display the string on the interface
long end=System.nanoTime(); //whenever the interface if opened, get the value of current time
long time=end-Main.begin; // end time minus start time
long timesec=time/1000000000; // divide to get the unit in second
long timemin=timesec/60; // divide to get the unit in minute
timeD.setText("App use time: "+timemin+" minutes"); // display time in minutes
}
catch(IOException e) {
System.out.println(e);
}
}
}