Creating first Java program

Discussion in 'Mac Programming' started by Yair1978, Jul 10, 2011.

  1. Yair1978 macrumors newbie

    Joined:
    Jul 10, 2011
    #1
    Hi,

    I've downloaded Eclipse and I've done my first "hello world" program in Java. Now, I just really want to produce a runnable file that I can click on using finder or from the desktop without having to settle for running it from within Java or from the console. Also, I'd like it to run within the usual mac interface, perhaps producing a window in which it says its "hello world".

    Can someone guide me through this? ;-)

    (I've looked around for tutorials but only such that seem to assume a different version of Eclipse pointing to jar files that I can't find...)

    /Yair
     
  2. canada eh macrumors regular

    Joined:
    Dec 22, 2009
    Location:
    Barrie, Ontario
    #2
    what you may be looking for is an applet or a desktop application to start. I use netbeans do i can't really guide you through it.

    Applets are usually run in a web browser where a desktop application is your typical application for the desktop. the simpler out of both of these would be the applet, which i recommend starting with. you should try googleing "first java applet eclipse".

    that should be a good start, with you just creating the hello world application you should experiment more with the console if you are a first time programmer and get familiar with loops and if-statements.
     
  3. pilotError macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #3
    You can right click on the package name you can choose export then a dialog will pop up, choose runnable jar file, pick the package and a place to put it and it will create a jar file that you just have to run.

    I'm not sure if you can just double click it though, I actually never tried it. I'm not sure how that would work anyway, as the output would go to a console, which you don't get when you double click the binary...

    Sorry, hopefully that works for you... Or at least points you in the right direction.
     
  4. SomeWhores macrumors newbie

    Joined:
    May 11, 2011
    #4
    I'd stick with command line utilities in Java before I'd even think about doing anything with a GUI.

    When I had to create a GUI in my Java class, it was probably the biggest, most tedious pain in the ass ever. If you want to learn about GUI creation, look into Java Swing and Java AWT. Those are the tools we used in my class.

    As for making a clickable application, you could use AppleScript to make an application ( not ideal but could be considered a work around ) with something like

    do shell script "cd <where the file is> "
    do shell script "javac -classpath . <nameOfFile>.java; java <nameOfCLass>"


    Granted that's probably a horrendous AppleScript, something like that could work.
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    It's also unnecessary.

    First, you don't need to compile the source every time.

    Second, if a jar-file contains a manifest with a main-class, and that class presents a GUI, then double-clicking the jar-file will run the GUI on Mac OS X.

    For more info, start with this:
    http://developer.apple.com/library/...va14Development/00-Intro/JavaDevelopment.html

    There's more available on developer.apple.com, but you'll have to search for it.

    Another search term to google for:
    jarbundler
     
  6. SomeWhores macrumors newbie

    Joined:
    May 11, 2011
    #6
    That is a far more awesome idea than I had. That's pretty awesome, I didn't know that was possible. For class we had to use command line to launch, and since I was constantly changing I needed to recompile.


    Do what chown33 said, his idea is far better than mine.
     

Share This Page