Archive for February, 2008

Controlling The Command Line with Java

I wrote this to launch some batch files from within an Java program. public class CmdExec { // process invoking program will call private Process p; // empty constructor public CmdExec() { } // execute command public void exe(String cmdline) { try { // string for system out String line; // create process p = [...]

Getting Text and Images from The Web with Java

I used this code to get images and text from the web. First an image: public static BufferedImage getImage(String urlString)throws Exception { // construct URL URL url = new URL(urlString); // get AWT image Image image = Toolkit.getDefaultToolkit().getImage(url); // cast to BufferedImage return ImageUtils.toBufferedImage(image); } Now to return all text as a String: public static [...]

Creating a Pause Method in Java

I use this often in my robotics code. The reason is simple, it takes the robots time to do things and I need to wait for a microcontroller to perform some action, like get a sensor reading, or move a certain distance, or change heading. It’s very simple, but I will add more robotics code [...]