Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Posts
    380
    Thanks
    36
    Thanked 25 Times in 25 Posts

    Can I use Java to...

    So I'm thinking about starting some Java project, but I want to know if I am able to do certain things before I even try.

    So, with Java, can you:
    - "dynamically" import packages
    -- Suppose it isn't possible. Is it possible to then include a package that includes all packages within that package? Such that any new package that appears in that package is included, and any package removed won't be in there anymore.

    - Have outer java class take priority over the classes in a jar
    e.g. Suppose I had a jar file that had the file MyProjectStart.java. In the same folder as that jar file, if there is another MyProjectStart.java and you run the jar file, is it possible to have the outer java file run instead of the jar's java file?

    - Minimize the project to "icon" bar [Windows]? Such that if the "X" or "Minimize" button are pressed, the program will be "hidden" from the task bar and is instead in the icon bar that is next tot he taskbar?

    - Dynamically create classes using strings. Such that if you loaded a string "Foo" you can create a class Foo (and probably send in some arguments).

    - Suppose some or all of these are possible. Is it possible to have these cross-OS compliant?


    Also, what GUI package should I look in that works for most OS and most Java versions?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    • You can dynamically import classes, but I don't think you can with a full package. You can of course load a class that does import many packages. The trick will be to give it a more meaningful datatype than that of Object. I'd recommend a simple interface which you can cast to.
      This is done using either reflection or the ClassLoader. Here's a link: http://tutorials.jenkov.com/java-ref...reloading.html
    • Priority in a jar, I'd say no. You have one chance to make an entrance class, and that cannot change. You can use a factory to select what to load based on some criteria though, which can be loaded from the filesystem.
    • You can run completely in the background by never discarding the gui. You can also make use of the task bar as well, let me find a link. Here we go: http://java.sun.com/developer/techni...e6/systemtray/
      Simply override the close operation to hide it instead of closing it.
    • Yes, see the first point. That is how you dynamically load the class since there is no way prior to this to determine its datatype. Once a class has been established, you may cast it as such. Seems unusual yes, but that is how you load. Once a 'class' has been determined as valid, it may then be cast from an Object to another type.
    • Java is platform independent. Use the swing library with as minimal use of AWT as you can. AWT is more widespread version wise of java, while swing is lighter weight so its better for platform independent development.

  • Users who have thanked Fou-Lu for this post:

    Apothem (12-03-2011)


  •  

    Posting Permissions

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