Sweet little Java Util I did! open source, enjoy!

Discussion about Irrlicht's Java wrapper
Post Reply
Systemerror
Posts: 98
Joined: Fri Oct 03, 2008 1:25 pm
Location: UK
Contact:

Sweet little Java Util I did! open source, enjoy!

Post by Systemerror »

Image
CheckOS Java version:

This is a simple utility to check which Operating System the client is running on and is done in Java, thus very platform independant providing they have the JRE installed which most computers today do, it comes with an executable so you can test it out straight away, and also the source code so you can edit and use it with future programs as you wish.



This is very similar to the C++ version but I think slightly better because it's more robust because of it's portability... however you may be thinking; "It's in Java, why would I need to check the OS" - right?
well there are a plethora of reasons one might find this useful, for example working with different files/directorys which changes between OS's, or another may be for example to check which version of your software needs downloading/installing etc, enjoy.

Download, Exe, classes, source code -> http://virtualworld.synthasite.com/reso ... ersion.zip

Source:

Code: Select all

/*
OS checker Java version by http://virtualworld.synthasite.com all rights reserved
*/


//import relevant resources
 import java.lang.*;
 import javax.swing.*;
 import java.awt.*;


//Create base class for OS checking components
 class OScheck  extends JFrame
 {


   //pub str to hold OS name variable
   public static String OS = null;
   //Text label for GUI
   JLabel label1 = new JLabel("Checking OS, wait...");


        //mathod for retrieving and calling OS name
        public String getOsName()
        {


           if(OS == null)
           {
           System.out.println("Loading...");
           OS = System.getProperty("os.name");
           System.out.println("The Operating System is :"+OS);
           JOptionPane.showMessageDialog(null ,"The Operating System is :"+OS);
           }

         return OS;


      }

            //check different OS types using boolean logic, getOSName() and StartsWith() functions



         //---note-- their are more than this so feel free to append some more

        public boolean isWindows()
        {
        return getOsName().startsWith("Windows");

        }
       



         public boolean isLinux()
         {
         return getOsName().startsWith("Linux");

         }
        
           public boolean isUnix()
          {
          return getOsName().startsWith("Unix");

          }
        
          public boolean isMac()
          {
          return getOsName().startsWith("Mac");

         }





              //finish function to be called


         public void Finished()
         {
           JOptionPane.showMessageDialog(null ,"Finished, press OK and close the window in top left corner."
           +"\n_________________________________\nhttp://virtualworld.synthasite.com - all rights reserved.");

         }




         /*
         GUI window in upper left to be used as a status window
         also the message dialogs probably wouldn't show in time on vista
         before the program ends due to the way vista and Java are aetup.
         */

         OScheck()
         {
           setTitle("OS check by Virtualworld");
           setSize(300, 100);
           setLocation(0,0);
           setResizable(false);
           setVisible(true);
           Container c = getContentPane();

            c.add(label1);



           setContentPane(c);

         }

}

//main class for calling all proir functions

public class CheckOperatingSystem
{
      public static void main(String[] args)
      {

       //initialize OScheck class
       OScheck OSC = new OScheck();


         //conditional if/else statements to call different parameters



                  if(OSC.isLinux())
                  {
                  System.out.println("Performing Linux only tasks.\n");
                  JOptionPane.showMessageDialog(null ,"Performing Linux only tasks.\n");
                  OSC.Finished();
                  }
            
                  else if(OSC.isWindows())
                  {
                  System.out.println("Performing Windows only tasks.\n");
                  JOptionPane.showMessageDialog(null ,"Performing Windows only tasks.\n");
                  OSC.Finished();
                  }
                 


                 
                   else if(OSC.isUnix())
                  {
                  System.out.println("Performing Unix only tasks.\n");
                  JOptionPane.showMessageDialog(null ,"Performing Unix only tasks.\n");
                  OSC.Finished();
                  }

                   else if(OSC.isMac())
                  {
                  System.out.println("Performing Mac only tasks.\n");
                  JOptionPane.showMessageDialog(null ,"Performing Mac only tasks.\n");
                  OSC.Finished();
                  }
                 
                 
                  //return this call if OS wasn't found
                  else
                  {
                   JOptionPane.showMessageDialog(null ,"Can not determine OS.\n");
                   OSC.Finished();
                  }



      }
}
[/img]
-System error
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Thanks for sharing. I've moved this to... ooooh, let's say Jirr, since I can't think of another suitable location.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply