我使用JavaFx创建了一个应用程序,当我使用Clean和Build构建项目时,它正在向我展示
注意:.. 路径 .. \ DemoScreenShot.java使用未经检查或不安全 操作
注意:使用-Xlint重新编译:取消选中以获取详细信息。
在dest文件夹中生成的可执行jar文件也显示错误:"Exception while running Application".
CODE:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package demoscreenshot;
import Stages.LoginStage;
import elements.ButtonPanel;
import elements.CalenderRegion;
import elements.CalenderTag;
import elements.CloseBox;
import elements.ConfirmBox;
import elements.NotificationDialog;
import elements.TaskSelectionPanel;
import elements.TimerElement;
import elements.TrackingPanel;
import java.io.FileNotFoundException;
import java.util.Date;
import java.util.Iterator;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.WorkerStateEvent;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.Separator;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.util.Duration;
import listener.ListenerController;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import tasks.DetectionService;
import tasks.SnapshotTask;
import tasks.TaskDetailsService;
public class DemoScreenShot extends Application {
Stage primaryStage;
LoginStage loginStage;
TaskDetailsService taskService;
VBox selectionPanelBox;
HBox buttonPanelBox, piHBox;
TaskSelectionPanel selectionPanel;
ButtonPanel buttonPanel;
ProgressIndicator pi;
Rectangle screenBounds;
NotificationDialog dialogStage;
Timeline timeline;
Timeline snapshotTimeLine;
Date lastDialogTime;
TrackingPanel trackingPanel;
VBox trackingPanelBox;
DetectionService detectionService;
TimerElement timerLabel;
Label idleLabel;
@Override
public void start(final Stage stage) throws FileNotFoundException {
screenBounds = new Rectangle(
Screen.getPrimary().getBounds().getWidth(),
Screen.getPrimary().getBounds().getHeight());
loginStage = new LoginStage();
this.primaryStage = loginStage.getLoginStage();
primaryStage.showAndWait();
if (loginStage.isLoginSuccessful()) {
primaryStage = stage;
primaryStage.setWidth(300);
primaryStage.setHeight(600);
final BorderPane borderPane = new BorderPane();
final VBox mainVBox = new VBox();
mainVBox.setAlignment(Pos.CENTER);
mainVBox.setMaxWidth(280);
mainVBox.setSpacing(15);
mainVBox.setPadding(new Insets(5, 5, 5, 5));
pi = new ProgressIndicator(-1);
pi.setMaxWidth(50);
piHBox = new HBox();
piHBox.setAlignment(Pos.CENTER);
piHBox.getChildren().add(pi);
//mainVBox.getChildren().add(pi);
selectionPanel = new TaskSelectionPanel();
selectionPanelBox = selectionPanel.getTaskSelectionBox();
selectionPanelBox.setVisible(false);
trackingPanel = new TrackingPanel();
trackingPanelBox = trackingPanel.getTrackingPanelBox();
trackingPanelBox.setVisible(false);
final GridPane trackSectionGridPane = new GridPane();
trackSectionGridPane.setAlignment(Pos.CENTER);
trackSectionGridPane.setPadding(new Insets(5, 5, 5, 5));
trackSectionGridPane.add(piHBox, 0, 1);
trackSectionGridPane.add(selectionPanelBox, 0, 1);
trackSectionGridPane.add(trackingPanelBox, 0, 1);
timerLabel = new TimerElement();
idleLabel = new Label();
HBox timerHBox = new HBox();
timerHBox.setMaxWidth(170);
timerHBox.setAlignment(Pos.CENTER_RIGHT);
timerHBox.getChildren().add(timerLabel);
mainVBox.getChildren().add(idleLabel);
mainVBox.getChildren().add(timerHBox);
mainVBox.getChildren().add(new Separator());
mainVBox.getChildren().add(trackSectionGridPane);
buttonPanel = new ButtonPanel();
buttonPanelBox = buttonPanel.getButtonPanelBox();
mainVBox.getChildren().add(new Separator());
mainVBox.getChildren().add(buttonPanelBox);
taskService = new TaskDetailsService();
taskService.setUserid(loginStage.loginService.getUserid());
taskService.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
@Override
public void handle(WorkerStateEvent t) {
if (taskService.getData().toString().equals("{}")) {
piHBox.setVisible(false);
Label notWork = new Label("No work is available for You.");
notWork.setStyle("-fx-text-fill: red;");
trackSectionGridPane.add(notWork, 0, 1);
} else {
noWorkSelectedPolling();
setDataToCombobox();
selectionPanelBox.setVisible(true);
}
}
});
taskService.start();
buttonPanel.startButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
//selectionPanelBox.setVisible(false);
trackingPanel.setProject(selectionPanel.projectComboBox.getValue().toString());
trackingPanel.setTask(selectionPanel.taskComboBox.getValue().toString());
trackingPanel.setSubTask(selectionPanel.subTaskComboBox.getValue().toString());
selectionPanelBox.setVisible(false);
trackingPanelBox.setVisible(true);
buttonPanel.startButton.setDisable(true);
buttonPanel.stopButton.setDisable(false);
buttonPanel.logoutButton.setDisable(true);
idleLabel.setText("");
if (dialogStage != null) {
dialogStage.close();
}
if (timeline != null) {
timeline.stop();
}
//Start activites
startTracking();
}
});
buttonPanel.stopButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
//Stop activites
sendScreenShotData();
stopTracking();
}
});
buttonPanel.logoutButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
primaryStage.setOpacity(0);
ConfirmBox confirmBox = new elements.ConfirmBox();
confirmBox.getConfirmStage().showAndWait();
if (confirmBox.getIsCofirmed()) {
//Stop everything
loginStage.loginService.doLogout();
Platform.exit();
primaryStage.close();
} else {
primaryStage.setOpacity(1);
}
}
});
CalenderTag calenderTag = new CalenderTag();
HBox calenderBox = calenderTag.getCalenderBox();
Scene scene2 = new Scene(new CalenderRegion("http://192.168.1.110:8080/ProjectManagement/"));
final Stage stage1 = new Stage();
stage1.setScene(scene2);
calenderTag.calendarLink.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
System.out.println("Open Calender");
if (stage1.isShowing()) {
stage1.hide();
stage1.close();
} else {
stage1.show();
primaryStage.setX(screenBounds.getWidth() - primaryStage.getWidth() - 50);
}
}
});
mainVBox.getChildren().add(calenderBox);
// Button addTask = new Button("Add Task");
//
// mainVBox.getChildren().add(addTask);
ImageView closeButtonImageView = new CloseBox().getCloseBoxImageView();
closeButtonImageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
primaryStage.setOpacity(0);
ConfirmBox confirmBox = new elements.ConfirmBox();
confirmBox.getConfirmStage().showAndWait();
if (confirmBox.getIsCofirmed()) {
if (buttonPanel.startButton.isDisable()) {
sendScreenShotData();
stopTracking();
}
loginStage.loginService.doLogout();
Platform.exit();
primaryStage.close();
} else {
primaryStage.setOpacity(1);
}
}
});
HBox hBox = new HBox();
hBox.setStyle("-fx-background-color: #5588bb;");
hBox.setMaxHeight(25);
hBox.setMinHeight(25);
hBox.setAlignment(Pos.TOP_RIGHT);
hBox.getChildren().add(closeButtonImageView);
borderPane.setCenter(mainVBox);
borderPane.setTop(hBox);
Scene scene = new Scene(borderPane);
scene.getStylesheets().add("css/myCSS.css");
primaryStage.setOnCloseRequest(
new EventHandler<WindowEvent>() {
@Override
public void handle(final WindowEvent event) {
primaryStage.setOpacity(0);
ConfirmBox confirmBox = new elements.ConfirmBox();
confirmBox.getConfirmStage().showAndWait();
if (confirmBox.getIsCofirmed()) {
if (buttonPanel.startButton.isDisable()) {
sendScreenShotData();
stopTracking();
}
loginStage.loginService.doLogout();
Platform.exit();
primaryStage.close();
} else {
primaryStage.setOpacity(1);
event.consume();
}
}
});
primaryStage.setScene(scene);
primaryStage.toFront();
primaryStage.show();
}
}
public static void main(String[] args) {
launch(args);
}
public void setDataToCombobox() {
ObservableList<String> projectOptions = FXCollections.observableArrayList();
Iterator keys = taskService.getData().keys();
while (keys.hasNext()) {
String project = (String) keys.next();
projectOptions.add(project);
}
selectionPanel.setData(taskService.getData());
selectionPanel.projectComboBox.setItems(projectOptions);
selectionPanel.projectComboBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> arg0, String arg1, String selectedproject) {
if (selectedproject != null) {
if (taskService.getData() == null) {
System.out.println("no data.. ");
} else {
try {
ObservableList<String> taskOptions = FXCollections.observableArrayList();
Iterator keys = taskService.getData().getJSONObject(selectedproject).keys();
while (keys.hasNext()) {
String task = (String) keys.next();
taskOptions.add(task);
}
selectionPanel.taskComboBox.setItems(taskOptions);
dialogStage.setTaskLeftToSelect("Task details");
selectionPanel.taskComboBox.setPromptText("Select your Task");
selectionPanel.taskComboBox.show();
selectionPanel.taskComboBox.hide();
selectionPanel.taskComboBox.requestFocus();
} catch (JSONException ex) {
ex.printStackTrace();
}
}
}
}
});
selectionPanel.taskComboBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> arg0, String arg1, String selectedtask) {
if (selectedtask != null) {
if (taskService.getData() == null) {
System.out.println("no data.. ");
} else {
try {
JSONArray subtasks = taskService.getData().getJSONObject(selectionPanel.projectComboBox.getValue().toString()).getJSONArray(selectedtask);
ObservableList<String> subTaskOptions = FXCollections.observableArrayList();
for (int i = 0; i < subtasks.length(); i++) {
String subtask = subtasks.get(i).toString();
if (subtask.equals("")) {
subTaskOptions.add(selectionPanel.taskComboBox.getValue().toString());
} else {
subTaskOptions.add(subtask);
}
}
selectionPanel.subTaskComboBox.setItems(subTaskOptions);
dialogStage.setTaskLeftToSelect("Sub task details");
selectionPanel.subTaskComboBox.setPromptText("Select your subtask");
selectionPanel.subTaskComboBox.show();
selectionPanel.subTaskComboBox.hide();
selectionPanel.subTaskComboBox.requestFocus();
} catch (JSONException ex) {
ex.printStackTrace();
}
}
}
}
});
selectionPanel.subTaskComboBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> arg0, String arg1, String selectedproject) {
if (selectedproject != null) {
if (taskService.getData() == null) {
System.out.println("no data.. ");
} else {
dialogStage.setTaskLeftToSelect("Project details");
buttonPanel.startButton.setDisable(false);
buttonPanel.startButton.requestFocus();
}
}
}
});
piHBox.setVisible(false);
selectionPanel.projectComboBox.show();
selectionPanel.projectComboBox.hide();
System.out.println("Done");
}
public void startTracking() {
timerLabel.startTimer();
startPollingForInactivity();
//Send screenshots and details
takeSnapShots();
}
public void stopTracking() {
selectionPanelBox.setVisible(true);
trackingPanelBox.setVisible(false);
buttonPanel.startButton.setDisable(false);
buttonPanel.stopButton.setDisable(true);
buttonPanel.logoutButton.setDisable(false);
timerLabel.stopTimer();
noWorkSelectedPolling();
//stop sending details
//Stop sending screenshots
System.out.println("Key: " + ListenerController.getNumberOfKeyPresses() + ", Mouse: " + ListenerController.getNumberOfMouseClick() + ", Time: " + timerLabel.getTimeMinute());
detectionService.setStop(true);
snapshotTimeLine.stop();
ListenerController.stopAllListeners();
}
private void noWorkSelectedPolling() {
//SHOW DIALOG INITIALLY
showDialog();
lastDialogTime = new Date();
//set task selected to false
dialogStage.setIsOkPressed(false);
if (timeline == null) {
timeline = new Timeline(new KeyFrame(Duration.seconds(0.5), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if (dialogStage.isOkPressed()) {
dialogStage.setIsOkPressed(false);
primaryStage.show();
primaryStage.toFront();
primaryStage.setFullScreen(true);
primaryStage.setFullScreen(false);
} else {
if (new Date().getTime() - lastDialogTime.getTime() > 10000) {
lastDialogTime = new Date();
showDialog(); // automatically on JavaFX thread, so can call restart directly
}
}
}
}));
timeline.setCycleCount(Animation.INDEFINITE);
}
timeline.playFrom("end");
}
private void showDialog() {
try {
dialogStage = NotificationDialog.getInstance(primaryStage);
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
if (!(primaryStage.isFocused())) {
dialogStage.makeAnimationTask();
dialogStage.displayInitially(screenBounds);
dialogStage.startAnimation();
} else {
dialogStage.hide();
}
}
Date snapshotInterval;
Date randomTime;
Date lastSnapshotTime;
boolean snapshotFlag;
int random;
private void takeSnapShots() {
snapshotInterval = new Date();
lastSnapshotTime = new Date();
randomTime = new Date();
random = 1 + (int) (Math.random() * ((loginStage.loginService.getSnapShotTime() - 1) + 1)); //snapshottime
snapshotFlag = false;
final TimerElement timerElement = new TimerElement();
timerElement.startTimer();
snapshotTimeLine = new Timeline(new KeyFrame(Duration.seconds(60), new EventHandler<ActionEvent>() {//60seconds
@Override
public void handle(ActionEvent event) {
if (new Date().getTime() - snapshotInterval.getTime() > loginStage.loginService.getSnapShotTime()) { //snapshottime
snapshotInterval = new Date();
randomTime = new Date();
snapshotFlag = false;
random = 1 + (int) (Math.random() * ((9 - 1) + 1));
System.out.println("random-" + random);
}
if (new Date().getTime() - randomTime.getTime() > (random * 60000)) {
if (!snapshotFlag) {
System.out.println("------------snapshot-----" + (new Date().getTime() - lastSnapshotTime.getTime()) + "--------");
snapshotFlag = true;
sendScreenShotData();
lastSnapshotTime = new Date();
}
}
}
}));
snapshotTimeLine.setCycleCount(Animation.INDEFINITE);
snapshotTimeLine.playFrom("end");
}
private void startPollingForInactivity() {
//start all listeners
ListenerController.startAllListeners();
detectionService = new DetectionService();
detectionService.setMaxIdleTime(loginStage.loginService.getIdleTime() * 60 * 1000);
detectionService.setStop(false);
detectionService.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
@Override
public void handle(WorkerStateEvent t) {
System.out.println("inactivity poll : " + t.getSource().getValue());
//stop all service and put it at stop mode
if (!detectionService.isStop()) {
idleLabel.setStyle("-fx-text-fill: RED;");
sendScreenShotData();
idleLabel.setText("You have been put to idle,\nPlease start again..");
primaryStage.show();
primaryStage.toFront();
primaryStage.setFullScreen(true);
primaryStage.setFullScreen(false);
}
//
stopTracking();
}
});
detectionService.start();
}
public void sendScreenShotData() {
SnapshotTask task = new SnapshotTask(screenBounds, loginStage.loginService.getUserid(), selectionPanel.projectComboBox.getValue().toString(), selectionPanel.taskComboBox.getValue().toString(), selectionPanel.subTaskComboBox.getValue().toString(), (int) (new Date().getTime() - lastSnapshotTime.getTime()) / 60000);
Thread th = new Thread(task);
th.setDaemon(true);
th.start();
}
}
我该如何解决这个问题?