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 :)
Ok... Anyone got any Idea how to get a pc's IP, Default Media player, Default Image Viewer, etc from java code?
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.
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
>>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.
What would really impress your teacher is if you implemented everything >>6 said as a class
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.
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 :)
>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).
Could I incorporate that section of the limewire support dll or whatever to do so then?
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.
>>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
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.
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.)
PROTIP: start.exe
>>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.)
It's only a year 12 thing =/