Need help with java :( (19)

1 Name: #!/usr/bin/anonymous : 2006-09-19 04:35 ID:h8clYPZ2

Ok, My teachers kinda suck and haven't really taught us much.
So... I'm meant to do something along these lines:

Using the Java programming language, you are to come up with a programming task that best demonstrates your level of technical programming, problem solving and creative design skills. You may chose a game, or any other task that will allow you to extend yourself in these areas. If you finish your task early, you should extend it or embark on an additional task. You have at least 7 full weeks of class time to work on your project.

It has to have a GUI, yada yada yada.

What I'm thinking of doing is a script compilation, open it up, little window pops up with a whole bunch of buttons for shutdown and web, Network connections... just a Windows start menu type thing in java language. Can't be that hard can it?

So yeah I know basics but nothing about GUI, pretty much the same for Java in General.

Any help is much Appreciated :)

2 Name: #!/usr/bin/anonymous : 2006-09-19 07:20 ID:3rtLlr+n

3 Name: #!/usr/bin/anonymous : 2006-09-20 02:34 ID:vCmK+V+c

Ok... Anyone got any Idea how to get a pc's IP, Default Media player, Default Image Viewer, etc from java code?

4 Name: #!/usr/bin/anonymous : 2006-09-20 08:03 ID:aoWEWmFN

You can get the IP several ways via the java.net package. The problem is that the PC will probably have several addresses and there isn't a reliable way to tell which, if any, is the primary. But you can instead get them all, along with the associated network interfaces, and let the user figure it out. NetworkInterface.getNetworkInterfaces() returns an Enumeration of NetworkInterface objects representing the interfaces, and the getInetAddresses() method of a NetworkInterface object returns an Enumeration of InetAddr objects representing the IP addresses bound to the interface.

5 Name: #!/usr/bin/anonymous : 2006-09-21 02:22 ID:h8clYPZ2

So based on the above, I take it that it's entirely possible for java to find default programs to run media, etc and provide shortcuts for them?

What I'm doing is a sort of shortcut menu much like Objectdock that provides basic functionality etc...

(It's for an assignment, so I'm doing something flashy)

-OP

6 Name: #!/usr/bin/anonymous : 2006-09-21 07:30 ID:aoWEWmFN

>>5
Not to my knowledge. It would be odd for something as platform-specific as application preferences to be included in the Java framework, given Java's emphasis on portability, but it might be in there somewhere. There's probably third-party library that wraps the relevant parts of the Windows API, but I have no idea.

A kinda lousy alternative that should work is using the ftype and assoc command-line utilites via java.lang.Runtime.exec(). You can use assoc to get the filetype for a given extension and ftype to get the application associated with the filetype. Pick some common filetypes, get the associations, and use them to create the shortcuts.

If you can get with just opening the files -- if you don't to know the actual apps -- I think you can just 'execute' a file and Windows will open it in the associated program.

7 Name: #!/usr/bin/anonymous : 2006-09-21 21:52 ID:AjBXt8t9

What would really impress your teacher is if you implemented everything >>6 said as a class

8 Name: #!/usr/bin/anonymous : 2006-09-23 03:32 ID:Heaven

IIRC there used to be a win.* class heirarchy available for Java, which could be used to write non-portable applications that did Windows-specific things. I dunno who published this or if it's still available/current or where one would get it if it is. Google may know these things, though.

9 Name: #!/usr/bin/anonymous : 2006-09-26 00:30 ID:vCmK+V+c

>>7

I could always trawl through the Limewire source code and find the whole "Default program" crap thats somewhere in it?

(Also, Someone give me a gui with a few buttons on it kgo :P)

But yeah, thanks heaps so far :)

10 Name: #!/usr/bin/anonymous : 2006-09-26 07:56 ID:aoWEWmFN

>>9

>I could always trawl through the Limewire source code and find the whole "Default program" crap thats somewhere in it?

No such luck. AFAIK Limewire calls into an included support DLL to open files. The DLL just passes the file to Windows and lets it figure out what app to use. I think the result is the same as "execute the file" suggestions in >>6 (assuming that works).

11 Name: OP : 2006-09-27 02:33 ID:vCmK+V+c

Could I incorporate that section of the limewire support dll or whatever to do so then?

12 Name: OP : 2006-09-27 03:13 ID:vCmK+V+c

Found this

String application = "";
eg. if ( itemClicked.endsWith(".pdf")) {
application = "acroread5";

try
{ Runtime.getRuntime().exec(application);
}
catch (Exception ex) {
}

It looks promising, so I'm gonna have a look at trying that once I get the program running.

13 Name: #!/usr/bin/anonymous : 2006-09-27 03:44 ID:aoWEWmFN

>>11
Check with your teachers. They might not want your pristine Java corrupted by native code and they really might not want to deal with C++/MFC and the Java Native Interface. If they don't mind, sure, go for it. Grab the Limewire source and look around gui/native/win. The file launching function is in JWindowsLauncher.cpp.

14 Name: OP : 2006-09-28 02:35 ID:vCmK+V+c

>>12

Would the above work though?

the limewire way looks pretty mind-blowing for my simplicity.

15 Name: #!/usr/bin/anonymous : 2006-09-28 05:37 ID:aoWEWmFN

>>14
Test it. That's the same solution I suggested in >>6 except I punted on figuring out what application to use and let Windows worry about it. (What happens if acroread isn't installed?)

The code as posted won't work because it's launching the application without passing it the file to be opened. You'd need something like

String[] cmdLine = {application, itemClicked};
Runtime.getRuntime().exec(cmdLine);

You'd have figure out exactly what command line syntax to use with each app.

16 Name: #!/usr/bin/anonymous : 2006-11-19 23:35 ID:vCmK+V+c

how do I go about repeating
if (file.getName().contains("wmv")) { applicationPath = "C:\\Program Files\\Windows Media Player\\wmplayer.exe"; }
Runtime.getRuntime().exec(applicationPath + " \"" + file.getAbsolutePath() + "\"");

then? do I just go else if? (Horribly stupid question, I know.)

17 Name: #!/usr/bin/anonymous : 2006-11-20 07:10 ID:Heaven

PROTIP: start.exe

18 Name: #!/usr/bin/anonymous : 2006-11-20 20:30 ID:INy3ai0K

>>16
If you were to do that, it would demonstrate how little Java you know. It would be far better to use a switch, or an object that implements an interface.

Rather than try something wanky, that demonstrates your knowledge (or ability to research) an esoteric subject in mind-numbing detail, you should be looking for a way to show off your Java/OO knowledge.

Forinstances might include an RPG, with a series of game.entity.monster s, and game.item s; Things like bags of holding are great for demonstrating that you understand inheritance. Or maybe a Geometry Wars clone, where everything is a subclass of ThingAffectedByGravity.

If you're set on writing a utility, how about a disk usage visualizer? Build a tree of directory objects, that calculate their space usage as and when the GUI needs the information, by finding out how big they are, and then adding the size of their children.

(If you want big marks, have a read through Head First Design Patterns, before attempting the exercise.)

19 Name: #!/usr/bin/anonymous : 2006-11-21 03:50 ID:h8clYPZ2

It's only a year 12 thing =/

This thread has been closed. You cannot post in this thread any longer.