Results 1 to 2 of 2
  1. #1
    victaino is offline Member
    Join Date
    Apr 2012
    Posts
    38
    Rep Power
    0

    Default Invoking mac Calculator in java

    I want to invoke mac or windows calculator at the click of a button in my project depending on the os. I have successful written the code for windows and im stuck at trying to get the code to invoke mac calculator work. below is my code:

    Java Code:
     // determine OS
        public static boolean isWindows(){
         String os = System.getProperty("os.name").toLowerCase();
         return (os.indexOf("win") >= 0);
        }
        
        public static boolean isMac(){
         String os = System.getProperty("os.name").toLowerCase();
         return (os.indexOf("mac") >= 0);
        }
    
    // method to invoke windows and mac calculator
    public void calculator(){
            // Display System Calculator
            if(isWindows()){
            try {
                Runtime.getRuntime().exec("calc");
            } catch (Exception e) {
            }
            }
            else if (isMac()){
              try{
                  Runtime.getRuntime().exec(" /Applications/Calculator.app");
                  
              }  catch (Exception ex){
                  
              }
            }
        }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Invoking mac Calculator in java

    One problem with the posted code is that it ignores exceptions. Add a call to printStackTrace() in all the catch blocks.

    Also add some printlns to show what the code is doing.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Java Calculator
    By SilverSoul in forum New To Java
    Replies: 3
    Last Post: 04-25-2012, 08:17 PM
  2. Calculator in java
    By andrewparent in forum New To Java
    Replies: 1
    Last Post: 04-20-2012, 09:36 PM
  3. Invoking Java Script
    By mehulshah in forum SWT / JFace
    Replies: 0
    Last Post: 01-05-2012, 08:04 AM
  4. help with basic sum calculator in java
    By java157 in forum New To Java
    Replies: 8
    Last Post: 03-18-2011, 12:12 AM
  5. Java Calculator
    By aapanju in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 06:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •