Wednesday, 24 September 2014

Creating a shutdown button using java Netbean GUI

Creating a shutdown using java NETBEAN is very easy, even if you are an amateur in the language. We’ll be creating one in GUI (graphical user interface). By this I mean using drag and drop and letting the system do some of the coding for you.
 Before we start there are some requirements you need they are JDK (java development kit) and your NETBEAN installer I will recommend netbean 7.1.2 it is what I am using and its ok. If you want more instructions on how to install the product you can check for instructions.


  • Open your NETBEAN. On the menu bar click on File => New Project.
  •  Under categories click java, under projects select Java application then click on next.
  • A second form pops up, on the project this is the form that lets you to insert your project name. Enter MyShutDown as project name, uncheck create as main class since we don’t want it to be our main class then click on finish.

  • The project is now created. To add a form or jFrame, Right click on MyShutDown under the project panel, click on New => JFrame form…
  • A pop up window appears Enter ShutDown for the class name. under the package name enter my.(name of the project) in our case it would be my.MyShutDown. click finish button a new interface pops up as shown below

  • From the palette menu at the right hand side of your screen, drag a button to the form. If you can’t find your palette on your screen just hold these keys down ctrl+shift+8.
  • Right Click on the button, and select Edit Text . Rename the button to Shutdown.
  • Right Click on the button again and select events => Action => ActionPerformed. The code menu appears inside of it (I.e where the cursor is blinking) type this code:
Runtime runtime=Runtime.getRuntime();
Process Proc=runtime.exec("Shutdown -s -t 0");
}catch(Exception e){

No comments:

Post a Comment