I'm trying to simultaneously learn Java, while making a program with it. I should note that I don't like taking baby steps, and like to jump right in...which is probably why I'm having problems.
So, yeah. I want a program that will launch COD4 and automatically connect to a server with an IP that I enter into a text box. Sure, I could use XFire or something, but then I'd have to make a favorite everytime. The purpose is for matches/scrims. I normally just copy paste the IP string (which looks like: /connect 1.2.3.4:28960; password asdf) into console and away I go. However, I am lazy.
So: click exe, gives me a text box, I enter that string ^ and it launches COD4 and connects me to the server. I have already done this in C# and it works (albeit slightly buggy). I'd like to learn Java and figured I'd try to port my program.
My problem is that I cannot for the life of me figure out how to make Java launch a program in its own working directory. I can launch the iw3mp.exe, but unless it is launched IN the working directory it will not be able to find the files to load and gives me missing IWD errors. I have Googled for hours, tinkered for hours, can't find a solution.
All I want to do at this point is make the game launch. I should be able to handle the rest, but I can't make this work and it's pissing me off. Please help.
So, yeah. I want a program that will launch COD4 and automatically connect to a server with an IP that I enter into a text box. Sure, I could use XFire or something, but then I'd have to make a favorite everytime. The purpose is for matches/scrims. I normally just copy paste the IP string (which looks like: /connect 1.2.3.4:28960; password asdf) into console and away I go. However, I am lazy.
So: click exe, gives me a text box, I enter that string ^ and it launches COD4 and connects me to the server. I have already done this in C# and it works (albeit slightly buggy). I'd like to learn Java and figured I'd try to port my program.
My problem is that I cannot for the life of me figure out how to make Java launch a program in its own working directory. I can launch the iw3mp.exe, but unless it is launched IN the working directory it will not be able to find the files to load and gives me missing IWD errors. I have Googled for hours, tinkered for hours, can't find a solution.
Code:
import java.io.*; import javax.swing.JOptionPane; public class cod4launcher { public static void main(String[] args)throws IOException { String serverIP = JOptionPane.showInputDialog(null, "Enter a Server IP!"); if (serverIP != null) { String file = "F:\\Games\\COD4\\iw3mp.exe"; Runtime.getRuntime().exec(file); } } }