Search This Blog

Showing posts with label computer. Show all posts
Showing posts with label computer. Show all posts

Java Code to Restart Windows

Are you thinking how to restart Windows from Java. You can restart Windows operating system by executing a system command. You can restart windows by executing the system command shutdown /r /t 1. The following Java code will restart the windows computer when executed.

try {
    Runtime.getRuntime().exec("shutdown /r /t 1");
    } catch (IOException ex) {}

How to Schedule a Shutdown in Java - Java Code to Schedule a Shutdown

In this post, we will see how to schedule a shutdown in a computer using java program. For this, we execute the appropriate shutdown command after identifying the operating system. The following java code will schedule a shutdown after a 10 minute from execution of the code.

String os=System.getProperty("os.name").toLowerCase();
String command;
try
{
if(os.contains("windows"))
    {
    command="shutdown /s /t 600";
    }
else if(os.contains("linux")||os.contains("mac os x"))
    {
    command="shutdown -h +600";
    }
else
    throw new Exception("Unsupported OS");
Runtime.getRuntime().exec(command);
}catch(Exception ex){
JOptionPane.showMessageDialog(null,ex.getMessage());
}

How to Shutdown Computer from Java - Java Code to Shutdown Computer

Java program can cause a computer to shutdown. In order to shutdown a computer using java code, you should execute the shutdown command in that operating system. The shutdown command is different in Windows and Linux. So, we first check for the operating system. Then we execute appropriate shutdown command.


try {
            String command;
            String os = System.getProperty("os.name").toLowerCase();
            if (os.contains("linux") || os.contains("mac os x"))
                command = "shutdown -h now";
            else if (os.contains("windows"))
                command = "shutdown /p";
            else
                throw new Exception("Unsupported operating system.");
            
            Runtime.getRuntime().exec(command);
            System.exit(0);

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }

For Linux and Mac OS X, the command for immediate shutdown is shutdown -h now. But in Windows, it is shutdown /p. The above java code checks the operating system. Then it assumes appropriate shutdown command and then executes it. This java code can shutdown a computer.

Plane Shooter Game for PC -Java Game Project with Source code

tank shoot down bomber planes free java game Multi level using Greenfoot .Plane Shooter is a single player lightweight Java game for Computers. It is a 2D game that works well even on  low end computers. The game size is only a few Kilobytes. You play as a tank and shoot down planes and what they drop. The game is in 7 or more levels. This is my first complete Greenfoot project. The source code of this game is also uploaded for those who want to see.

PanzerFight - Two player Action Game (Java Game) For Any OS

multi player Tank fight game free download for Windows Linux MAC and Solaris in Java Greenfoot platform mines shoot
PanzerFight is an interesting two player game for PC. The game is played between two players on same computer (can be on same keyboard). Each player controls a tank. The tanks can plant land mines or fire each other. Ammunition and health are supplied at times. The game is interesting since it is a multi player game. This multiplayer shooting game is supported on, Windows, Linux, Solaris, Mac etc. The game is developed in Java platform (using Greenfoot). JRE (Java Run time Environment) is a prerequisite to run this game.