mardi 10 mars 2015

Log off windows and Abort not working in JAVA


Vote count:

0




I'm creating my first fully functional java applet which can shutdown/restart my pc and log off on a specified time(in minutes)


The restart and shutdown function works, but not the abort and log off.


Here is the code for the abort and log off which is both in their own classes and called from a main:



//abort tasks

@Override
public void run() {

Runtime runtime = Runtime.getRuntime();
try {
Process proc = runtime.exec("shutdown -a -t 0");
} catch (IOException e) {
e.printStackTrace();
}
// System.exit(0);

}


// log off task



@Override
public void run() {

Runtime runtime = Runtime.getRuntime();
try {
Process proc = runtime.exec("-l -t 0");
} catch (IOException e) {
e.printStackTrace();
}
// System.exit(0);

}


private void cancelAction() {



AbortTask abort = new AbortTask();
abort.run();
abort.cancel();

}

private void starttimer() {

try {

Action();
if (RbShutdown.isSelected()) {

lblstatus.setText("Windows shutting down...");
lblstatus.setStyle("-fx-text-fill: red");
} else if (RbRestart.isSelected()) {
lblstatus.setText("Restarting....");
lblstatus.setStyle("-fx-text-fill: red");
} else if (RbLogoff.isSelected()) {
lblstatus.setText("Logging off...");
lblstatus.setStyle("-fx-text-fill: red");
} else if (RbShutdown.isSelected() && btnCancel.isPressed()) {
lblstatus.setText("Canceled!");
lblstatus.setStyle("-fx-text-fill: green");

}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}

public void Action() {

int time = Integer.parseInt(txfTimer.getText().trim());
ShutDownTask shutdownTask = new ShutDownTask();
RestartTask restartTask = new RestartTask();
LogOffTask logoff = new LogOffTask();
AbortTask cancel = new AbortTask();
TimerClass timer = new TimerClass(time);

try {
if (btnStartTimer.isPressed() && RbShutdown.isSelected()
&& timer.equals(timer)) {
shutdownTask.run();

} else if (btnStartTimer.isPressed() && RbRestart.isSelected()
&& timer.equals(timer)) {
restartTask.run();
} else if (btnStartTimer.isPressed() && RbLogoff.isSelected()
&& timer.equals(timer)) {
logoff.run();
} else if (btnStartTimer.isPressed() && RbShutdown.isSelected()
|| RbRestart.isSelected() || RbLogoff.isSelected()) {
cancel.run();
}

} catch (Exception e) {
e.printStackTrace();
}
}


asked 2 mins ago







Log off windows and Abort not working in JAVA

Aucun commentaire:

Enregistrer un commentaire